I am using webshim library, I need to compare two text field values to avoid duplicates and want to set custom validation message.
<form action="sample.html" method="post">
<label for="country1">Country 1 </label>
<input type="text" value="" id="country1" name="country1" required/>
<label for="country2">Country 2 </label>
<input type="text" value="" id="country2" name="country2" required />
<input type="button" value="submit" />
</form>
<script>
$(document).ready(function(){
$("#formsubmit").click(function(){
if($('form').checkValidity()){
if($("#country2").val()!= $("#country1").val()){
$("#country2").addClass('valid').removeClass('invalid')
$('form').submit();
}else{
$("#country2").addClass('invalid').removeClass('valid').setCustomValidity('Please Enter different country ');
}
}
});
});
</script>
On Fist time submitting the form if the two text field values are same the Custom validity message get replaced as defined. but when changing the "country 2" value the field remains invalid and form is not getting submitted.
Thanks