I've been trying to write Jquery code to check if two inputs have the same value on form submit without luck.
If input with id "id1" has the same value as input with id "id2" alert "some text" and return false.
Any help would be much appreciated.
$('#form').submit(function() {
var id1 = $(#id1).text();
var id2 = $(#id2).text();
if (id1 == id2) {
alert('Error, cant do that');
return false;
}
else
{
return true;
}
});
#id1must be'#id1', andtext()won't retrieve the value of an input field (why do you think it does?), use.val()instead. jQuery's documentation is pretty good and it's the first thing you should read if you are unsure about methods. Simply printingid1andid2would have been a good start for debugging.