I have a form with many fields and 2 submit buttons. I want to run a different check depending on which submit button i click on. I tried writing the code below but it is wrong (i dont know JS) and nothing happens (bad syntax?). How do i figure out which of the two buttons was clicked?
document.getElementById('sub1').onclick = checkForm;
document.getElementById('sub2').onclick = checkForm;
function checkForm(e)
{
var e = e || window.event;
var o = e.srcElement || e.originalTarget;
if(o.id=="sub1")
return checkNotNull();
else
return checkSamePass();
}
I put your code into a test page, and it works fine on both FF and IE. The problem likely lies with the two functions you are calling,
checkNotNull()andcheckSamePass(). I would check that they are working and are properly returning.You can verify that the
o.idis correct by the time it gets to the if/else statement by putting in analert(o.id).