Forum Moderators: open

Message Too Old, No Replies

onsubmit + "disabled=true" = empty form?

Using onsubmit together with the disabled flag seems to send an empty form

         

orbilius

3:15 pm on Aug 27, 2004 (gmt 0)



Hi everybody!
I'm trying to write a form where the "Submit" button gets disabled when the user hits it the first time.
I first tried to use an "onclick" on the button disabling it, but realized that the form was not sent then. So now i'm trying to use "onsubmit" on the form to disable the button AND send the form. This is my (simplified) code:

function disableSubmit() {
myForm.myButton.value = "Processing...";
myForm.myButton.disabled = true;
return true;
}
...
<FORM onSubmit="return disableSubmit();" ACTION="test.abc" NAME="myForm" METHOD="POST">
...
<INPUT TYPE="SUBMIT" VALUE="Confirm" NAME="myButton"/>

This will make the page post an empty form to the "test.abc" page! It seems to be the line "myForm.myButton.disabled = true;" that causes the empty form posting, because if i use only the "myForm.myButton.value = "Processing...";" line, everything works fine (except of courcse that the button does not get disabled, which is what i wanted!)

I'm using IE 6.0 on W2K.

Clues, anyone?

Birdman

4:27 pm on Aug 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I haven't actually tried this, but it sure seems like it would work ;)

formClicked = false;

function disableSubmit() {

if (formClicked == false){
formClicked = true;
myForm.myButton.value = "Processing...";
return true;
} else {
return false;
}

}

StupidScript

5:36 pm on Aug 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This works for me:

<input type="submit" value="Submit" onClick="this.disabled=1;this.value='Processing...';">

The form goes to the submit process normally, independent of what has happened to the button's state.

Note that if you are running a form validation routine, you want to re-enable the button if validation fails, to give the user a chance to fix things and re-submit.