I need to check if a value has changed on an input field before submitting a form. This is the code I have so far:
JS
$(document).ready(function(){
$('#submitButton').click(function() {
if( $('input[name="inputToBeChecked"]').val() != 'Original input field value' {
alert("Input field has changed!");
} else {
alert("Input field has not changed!");
}
});
});
HTML
<form>
<input type="text" name="inputToBeChecked" id="inputToBeChecked" value="Original input field value">
<a id="submitButton" type="button" class="btn" href="javascript:void(0);">Submit form</a>
</form>
)if yourif/else)on your if statementdata-*attribute to avoid having variables for each input you're interested to do this with.. but if you fix your typo the basics are ok :)