[Javascript] disabling form on submit

Paul Novitski paul at novitskisoftware.com
Mon May 24 13:38:53 CDT 2004


Shawn Milo wrote:
>Disabling the submit button 'onsubmit' causes a problem if the
>page which accepts the submitted form relies on the value of
>the submit button to decide which action to take, because
>disabling the button on submit causes the button to return
>no value.

And then he wrote:
>Onsubmit, if the value of the submit
>button == 'Please Wait', return false.
>
>Onsubmit, change the value of the
>submit button to "Please Wait".


Ah, you've stirred the sediment enough for some old logic to burble up 
through the murk.

Here are two submit buttons, both calling the same submit routine:

<input
  type="submit"
  name="verbEdit"
  value="Edit Item"
  onclick="jsSubmit()"
 >

<input
  type="submit"
  name="verbDelete"
  value="Delete Item"
  onclick="jsSubmit()"
 >

...

var bSubmitted = false
var sSendingPrompt = "Please wait..."

function jsSubmit()
{
         // allow submit to happen only once
                 if (bSubmitted) return false
         bSubmitted = true

         // change the button face to "wait" prompt
         this.value = sSendingPrompt

         // allow the form to submit
         return true
}

On click, the clicked button changes to a Wait prompt.

Only one form submission is permitted to occur.

Per HTML, when the markup contains multiple submit buttons only the one 
that's clicked shows up in the form element array.

Because the button face text *is* the value of the submit button, the 
server-side script looks for a form element named "verbEdit" or 
"verbDelete" and ignores its value.

As I recall, I couldn't change the button face text with the direct statement:
         this.value = "Please wait..."
but instead had to use a variable for some mysterious reason...

Paul 





More information about the Javascript mailing list