if(!submitButton.form) { alert("parentless button (no form)"); return; }
var formElements = submitButton.form.elements;
for(var i=0; i<formElements.length; i++) { //leave the pressed button as is... if(formElements[i] == submitButton) continue;
//disable all other submit buttons if(formElements[i].type == "submit") { formElements[i].disabled = "true"; } } }
How to use it: <form action="showRequestVariables"> <button type="submit" name="button1" onClick="disableOtherSubmitButtons(this)">Button1</button> <button type="submit" name="button2" onClick="disableOtherSubmitButtons(this)">Button2</button> </form>
Comment
For those who are interested:
function disableOtherSubmitButtons(submitButton)
{
if(!submitButton)
{
alert("no object found");
return;
}
if(!submitButton.type)
{
alert("no type attribute");
return;
}
if(submitButton.type != "submit")
{
alert("no submit button");
return;
}
if(!submitButton.form)
{
alert("parentless button (no form)");
return;
}
var formElements = submitButton.form.elements;
for(var i=0; i<formElements.length; i++)
{
//leave the pressed button as is...
if(formElements[i] == submitButton)
continue;
//disable all other submit buttons
if(formElements[i].type == "submit")
{
formElements[i].disabled = "true";
}
}
}
How to use it:
<form action="showRequestVariables">
<button type="submit" name="button1" onClick="disableOtherSubmitButtons(this)">Button1</button>
<button type="submit" name="button2" onClick="disableOtherSubmitButtons(this)">Button2</button>
</form>