Hi,
I have to disable the Submit button after a form has been submitted, but I do no find the right way to do it.
B1 works fine, but does not disable the button.
B2 disables the button, but does not submit the form.
B3 disables the button and submits the form, but also skips the validation routine (testForm()).
I guess I could solve the problem in the code of the validation routine or in the first line of code of the form, but the buttons are dinamically generated through a function that is called from several pages which all use different form names and validation routines names, so I would like to do it in the line with the buttons code.
I would also like to avoid the "visibility = hidden" property.
Any hints?
vlad
I have to disable the Submit button after a form has been submitted, but I do no find the right way to do it.
Code:
<form action ="javascript:alert('Submited');" name = "test" onSubmit = "return testForm();">
<input type = "text" name = "t" />
<br />
<input type="submit" value="Submit1" name="B1" onclick="return confirm('Confirm this to submit the form.')">
<br />
<input type="submit" value="Submit2" name="B2" onclick="B2.disabled = true; return confirm('BlaBlaBla')">
<br />
<input type="submit" value="Submit4" name="B4" onclick="B4.disabled = true; if(confirm('BlaBlaBla')) document.forms[0].submit();">
</form>
<script language = "JavaScript">
function testForm()
{
if(test.t.value != "")
{
alert("Testing - OK!");
return true;
}
else
{
alert("Testing - ERROR!");
return false;
}
}
</script>
B1 works fine, but does not disable the button.
B2 disables the button, but does not submit the form.
B3 disables the button and submits the form, but also skips the validation routine (testForm()).
I guess I could solve the problem in the code of the validation routine or in the first line of code of the form, but the buttons are dinamically generated through a function that is called from several pages which all use different form names and validation routines names, so I would like to do it in the line with the buttons code.
I would also like to avoid the "visibility = hidden" property.
Any hints?
vlad