44 Posts
Tina
12 days ago
0
Topic

I would like to compare two text fields, if they are the same, don't allow the user to save the form using the submit button. I added code to the button in the Javascript are in the field. It did not work:

document.getElementById("My_submit_button").onclic = function() {myFunction()};

function myFunction(){

name1=document.getElementById("name1").value();

name2=document.getElementById("name2").value();

if (name1 === name2){

alert("Please change the names.");

return false;

}

return true;

}

I also tried this too in the submit button javascript area. The preventDefault() would prevent the submit to work but then it just would never work even after I changed the field text and pressed the submit button again.

$(document).ready(function(){

$('$seblod_form').submit(function(e){

var name1=$('#name1').val();

var name2=$('#name2').val();

if (name1 === name2){

alert("Please change names.");

e.preventDefault(e);

}

});

});

Get a VIP membership