Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick disable buttons onSubmit question for you experts. 1

Status
Not open for further replies.

Markh51

Programmer
May 20, 2003
81
0
0
GB
I have two buttons on the bottom of my form (YES & NO). Both buttons will submit the form to itself and then determine where to go depending on the button pressed.

What I want is to be able to disable both of the buttons when you click YES and continue to submit the form, but just submit the form normally if you clik NO.

Thanks in advance.
 
in the onclick element of the yes button add these 2 lines:

Code:
formName.yesButton.disabled=true;
formName.noButton.disabled=true;

formName being the name of the form that is parent to the buttons, and yesButton/noButton being the names of the respective buttons

-kaht

banghead.gif
 
I have tried that, but when you click on the button, it DOES disable but the form does NOT submit.

This is what I was saying the form must be submitted after disabling the button.

I don't want to add:
document.form1.submit();

to the JS code either, because my page has to be compatible if the user has JS disabled. I know the buttons won't be disabled but the the form must get submitted either way.

I have tried using ONSUBMIT, but I can not work out how to tell which button was clicked. If you can tell me how to do that, then I can get it to work OK.

Many Thanks.
 
Set a hidden flag on your page, and check for the status of that flag before you disable anything:
Code:
<script language='Javascript'>
function disableButtons() {
   if(blahForm.blahHidden.value == 1) {
      blahForm.yesButton.disabled = true;
      blahForm.noButton.disabled = true;
   }
   return true;
}
</script>
<body>
<form name='blahForm' onsubmit='disableButtons()'>
<input type=hidden name='blahHidden' value=0>
<input type=submit name='yesButton' value=yes onclick='blahForm.blahHidden.value=1'>
<input type=submit name='noButton' value=no onclick='blahForm.blahHidden.value=0'>
</form>
</body>

-kaht

banghead.gif
 
Cheers mate, it worked like a charm.

Thanks ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top