I am trying to use sample code from the help files to accomplish this task, but am not having any luck. Perhaps there is something interfering in one of the other Jquery lines I have written? Below is the full code.
This script is successfully hiding a Country, renaming "State / Province / Region" to just "State", and preventing zip code from being anything but 5 digits long. The last thing I need it to do is make sure that two e-mail address fields do not match; the fields are in classes "applicantemail" and "caoemail".
$(document).ready (function () { $(".Country").parent().children().val("USA"); $(".Country").parent().children().css('display', 'none'); $(".State").parent().children().val("TX"); $(".State").siblings().text('State'); $('.applicantemail, .caoemail').on('blur input', function () { if ($('.applicantemail input').val() == $('.caoemail input').val()) { $('.Submit').attr("disabled", "disabled"); if ($('.warningText').length > 0 || $('.caoemail input').val() == ''){ return; } else { $('<p class="warningText">The email addresses you entered for the Applicant and Chief Administrative Officer must not be the same.</p>').insertAfter('.caoemail'); } } else $('.warningText').remove(); $('.Submit').removeAttr('disabled'); var re = new RegExp("^\\d{5}$"); $('.Postal').on('change', function() { var s = parseNumber($(this).val()); $('p.zipWarning').remove(); if (re.test(s)) { $('.Postal').val(s); $('.Submit').removeAttr('disabled'); } else { $('.Postal').val("0"); $('<p class="zipWarning">Please enter a 5 digit zip code.</p>').insertAfter('.Postal'); $('.Submit').attr('disabled', true); } }); function parseNumber(n) { var f = parseFloat(n); //Convert to float number. return isNaN(f) ? 0 : f; //treat invalid input as 0; } })
Note: the first e-mail field with class .applicantemail is inside a table with 1 fixed row, so it lays out the information better. Not sure if this impacts.