Well, I got the validation function to do the trick so thank you. However, I am stuck on a new issue and would sure appreciate any help as I’ve been banging on this for several hours with no luck.
When the Eform snippet is called, and validation fails for any field, it reloads the page and set my drop down box value to undefined. This causes my dynamic Div display to fail since it is looking for the option value to determine which text field (phone or email) should be displayed.
My select box has 2 options - phone and email.
By default, I want the phone option to be selected and I want the phone text field to be displayed. Therefore, I’ve set the phone div to display when the page initially loads. This is why it gets out of sync when say the email option is selected and validation fails...after the page reloads the phone div gets shown by default again.
<div id="Phone" style="display:block">
<label for="quote_phone">Phone Number: (<i>Required</i>)
<input name="quote_phone" id="quote_phone" class="text" type="text" eform="Phone Number:string:0 /> </label>
</div>
<div id="Email" style="display:none">
<label for="quote_contact_email">Contact Email: (<i>Required</i>)
<input name="quote_contact_email" id="quote_contact_email" class="text" type="text" eform="Contact Email:email:0" /> </label>
</div>
The onchange property for the select box calls the javascript which will turn the right div on and off based on the current value. This works fine.
<label for="quote_contact_choice">How would you like to be contacted?
<select name="quote_contact_choice" id="quote_contact_choice" onchange="set_contact_field(document.QuoteForm.quote_contact_choice.value)">
<option value="Phone">Phone</option>
<option value="Email">Email</option>
</select></label>
This is the Javascript:
function set_contact_field(op) {
document.getElementById('OptionValue').innerHTML = op;
if (op == "phone") {
document.getElementById('Phone').style.display="block";
document.getElementById('Email').style.display='none';
}
if (op == "email") {
document.getElementById('Email').style.display="block";
document.getElementById('Phone').style.display='none';
}
}
When the page reloads after an Eform validation, the previous values for all text boxes are still populated and in fact the drop down box is still selecting the last choice (Email)...yet the value is now undefined. So the drop down box is showing "email", the validation error says "Please enter a valid email", and yet the phone text box is being shown instead of the email text box.
What I had tried is to not just call my Javascript during the onchange, but also call it again just after the html Divs in the hopes that it would correct the text box displayed. Since the value comes back undefined, it isn’t going to help.
I hope that makes sense. Not sure what to do.