I'm creating a dynamic form. I have a dropdown list which when the user makes a selection, the database is queried to see if the item required privacy or not. If it doesn't then additional fields are added to the form. Also a zip code lookup ajax function is triggered, but should only be triggered if the item is not private.
This is all working fine, until a user changes their mind...
Here is the relevant part of my code that runs when ever an item is selected from the dropdown;
success:function(response){
if(response === '1'){
// do stuff for item that requires privacy
// do NOT trigger zip_check function
}else if(response === '0'){
// do stuff for item that is public +
$('#zip-code').keyup(zip_check); // triggers a function to check zip code
}
}
This works as expected until a user selects a non private item then changes their mind and selects a private item in which case the zip_check function will still run even though it now shouldn't be getting triggered. Where am I going wrong?
try this:
for binding:
$('#zip-code').on('keyup',zip_check);
and for unbinding:
$('#zip-code').off('keyup',zip_check);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With