469,275 Members | 1,552 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Submitting A Form

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?

Nov 2 '06 #1
4 2659
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?
Nov 2 '06 #2
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.
Nov 2 '06 #3
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.
So*****@gmail.com 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?
Nov 2 '06 #4
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.
Nov 2 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Display Name | last post: by
2 posts views Thread by Greg T | last post: by
1 post views Thread by Richard Dixson | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.