We have a form that contains two Address fields. The "Mailing Address" is a required field and the "Street Address" is not. We have also added a javascript drop-down menu for the State information and a script to add "USA" as the default for "Country". As you can see from the screenshot of the form, the "Street Address" is still requiring a value for the State. I have also attached a screenshot of the javascript. Is there a way to modify the script so that it doesn't require a value for the "Street Address?"
Question
Question
Modifying Two Address Fields with Drop-down for State Information
Answer
Your current javascript will replace all elements that have the "State" class with the same select list using the same name, id, and other attributes, even required.
What you can do is target the individual fields and replace the respective inputs with its own select list, but making one required and one not required.
See the below example based off of a form that only has two address fields. Field1 is required and Field2 is not required. Then you can use
$(document).ready (function () { $(".Country").parent().children().val("USA"); $('input[name=Field1_DSG3]').replaceWith('<select name="Field1_DSG3" class="form-item-field required State" vo="e" required="required" id="Field1_DSG3">' + '<option></option>' + '<option value="Alabama">AL</option>' + '<option value="Alaska">AK</option>' + '<option value="Arizona">AZ</option>' + '<option value="Arkansas">AR</option>' + '<option value="California">CA</option>' + '</select>'); $('input[name=Field2_DSG3]').replaceWith('<select name="Field2_DSG3" class="form-item-field State" vo="e" id="Field2_DSG3">' + '<option></option>' + '<option value="Alabama">AL</option>' + '<option value="Alaska">AK</option>' + '<option value="Arizona">AZ</option>' + '<option value="Arkansas">AR</option>' + '<option value="California">CA</option>' + '</select>'); })
Replies
That worked. Thank you very much, Alexander!
Since there are many instances that forms will require two address fields and the address fields will frequently match (e.g., mailing address and street address, shipping address and billing address), it may be more efficient to duplicate the address field by checking a box. As you can see from the screenshot, all of the street address fields are automatically filled with the specified mailing address, except for the state field which has been modified for a drop-down list for the state information.
Below is the code that modifies the state field and automatically fills the street address fields. Any ideas why the state field is not being filled and how the code should be changed?