I have a web app where I need to display a set of input text boxes if the applicant has a US address; if the applicant has a non-US address, some of the US text boxes are disabled and some previously disabled text boxes are enabled (basically toggles on/off Non US Address boxes and US address boxes).
This is the code I currently have. It works with JQuery 1.7 but .change(fn) and perhaps other parts of the code appear to be deprectated in more recent versions of JQuery. I'm new to JQuery, so I'm not sure how to rewrite this. I haven't been able to find any examples on Google.
$(document).ready(function() {
$('#ForeignAddress').change(function() {
if ($(this).attr('checked')) {
$('#nonUSAddress').removeAttr('disabled');
$('#USAddress').attr('disabled', 'disabled');
} else {
$('#nonUSAddress').attr('disabled', 'disabled');
$('#USAddress').removeAttr('disabled');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form>
<p><input id="ForeignAddress" type="checkbox" /> Foreign Address</p>
<input id="nonUSAddress" type="text" value="NON US ADDRESS" disabled="disabled" />
<input id="USAddress" type="text" value="US ADDRESS" />
</form>
The snippet currently works because of the version of JQuery I've chosen, but if I set it to more recent JQuery, it doesn't work. If someone could provide an example of how I should write this without using the deprecated shortcut code, that would be great. Thank you!