Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Submitting A Form

Reply
Thread Tools

Submitting A Form

 
 
Super Steve
Guest
Posts: n/a
 
      11-02-2006
I'm trying to write a little script that disables the submit button on
a form, changes the text of the button, and then submits the form.

Can anyone tell me why this works ok:

<input type="button" value="Submit" onClick="this.disabled=true;
this.value = 'Submitting...'; this.form.submit();">

But when I try to make a function it doesn't work:

<script language="JavaScript">
function DisableButton(b) {
b.disabled = true;
b.value = 'Submitting...';
b.form.submit();
}
</script>

<input type="button" value="Submit" name="submit"
onClick="DisableButton(this);">

When I try this the button text is changed and the button is disabled,
but the form doesn't submit. In IE I get an error that points to the
line that says:

b.form.submit();

and the error:

Object doesn't support this property or method

What's the difference between doing this code directly in the onClick
event and doing it in a function?

 
Reply With Quote
 
 
 
 
Sova.tm@gmail.com
Guest
Posts: n/a
 
      11-02-2006
because b=to the button not to the form the riht syntax should be:

window.document.FormName.submit();



> b.form.submit();
>
> and the error:
>
> Object doesn't support this property or method
>
> What's the difference between doing this code directly in the onClick
> event and doing it in a function?


 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      11-02-2006
Super Steve wrote:
> I'm trying to write a little script that disables the
> submit button on a form, changes the text of the button,
> and then submits the form.
>
> Can anyone tell me why this works ok:
>
> <input type="button" value="Submit" onClick="this.disabled=true;
> this.value = 'Submitting...'; this.form.submit();">
>
> But when I try to make a function it doesn't work:
>
> <script language="JavaScript">
> function DisableButton(b) {
> b.disabled = true;
> b.value = 'Submitting...';
> b.form.submit();
> }
> </script>
>
> <input type="button" value="Submit" name="submit"
> onClick="DisableButton(this);">
>
> When I try this the button text is changed and the button is
> disabled, but the form doesn't submit. ...

<snip>

<URL: http://jibbering.com/faq/faq_notes/f....html#faComMis >

Richard.


 
Reply With Quote
 
Super Steve
Guest
Posts: n/a
 
      11-02-2006
Thanks for your reply. Initially I thought the same as you, but then I
read that every form element also had a "form" property that points to
the form that the element is an item of.

"All form element objects also have the form property, which returns
the Form object in which the element is contained. This can be useful
in cases where you have a generic routine that checks the validity of
data in a form. For example, when the user clicks a submit button, we
can pass the Form object referenced by the form property to our data
checker which can use it to loop through each element on the form in
turn, checking that data in the element is valid. This is handy if you
have more than one form defined on the page or where you have a generic
data checker that you cut and paste to different pages - this way you
don't need to know the form's name in advance."

So I don't know why b.form.submit.() doesn't work when b is pointing to
the button element within the form.


http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> because b=to the button not to the form the riht syntax should be:
>
> window.document.FormName.submit();
>
>
>
> > b.form.submit();
> >
> > and the error:
> >
> > Object doesn't support this property or method
> >
> > What's the difference between doing this code directly in the onClick
> > event and doing it in a function?


 
Reply With Quote
 
Super Steve
Guest
Posts: n/a
 
      11-02-2006
Awsome, Richard!

Well that's a trap for your players. I've always named my submit
buttons "submit" in the past, but then I've never tried to access them
with JavaScript before. Changing the name to "submitform" now makes
everything work.

Many thanks for your help!


Richard Cornford wrote:

> <URL: http://jibbering.com/faq/faq_notes/f....html#faComMis >
>
> Richard.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Form within a Form - will it cause problems when submitting? Dave Smithz HTML 3 10-30-2009 07:24 AM
Re: Page does not refresh after submitting form Mike Szanto ASP .Net 1 02-04-2005 06:17 PM
Submitting form from another frame does not run onsubmit of that form Kai Grossjohann Javascript 4 12-09-2003 02:49 PM
submit opener form after submitting pop-up form Marco Alting Javascript 7 10-30-2003 01:46 PM
Submitting form with a unique ID James Brown ASP .Net 2 07-06-2003 12:09 AM



Advertisments