I have a form which is submitted via a submit
button. When it is clicked it performs java script validation and shows error fields under the text box . So if there are errors, the control returns back to same page. My problem is that after form post, i keep on seeing two error fields and i need to delete one and keep only one .
For that, i called a click function from the submit button and there i am trying to find out if the error div ids exist like this :
<input type="image" name="submit" onclick = 'checkErrors()'>
Now inside the checkErrors()
method :
function checkErrors(){
var errorElem1 = document.getElementById('errField1');
var errorElem2 = document.getElementById('errField2');
if((errorElem1 != null) && (errorElem2 != null)){
alert("Two error fields.");
errorElem2.style.display='none';
}
}
Now, here i do not find the alert, once i click on the button.
So i removed the if condition and kept it as :
function checkErrors(){
var errorElem1 = document.getElementById('errField1');
var errorElem2 = document.getElementById('errField2');
errorElem2.style.display='none';
}
}
Now, i see error in firebug console : elem2 is null
. That means the onclick
is getting executed and then only form post happens, hence the elem2
is never found after onclick.
The form is submitted as :
<form name="IntitalJspPage" method="post" action="Controller" onsubmit="validate(this); return false;">
Now what can i do here to get the onclick called after the form has been submitted and the error fields have been rendered on the page ?