473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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 2775
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Display Name | last post by:
the customer I'm developing a site for uses a canned form-parsing page that allows her to have an email subscription opt-in page add emails to a list she can manage using a link that you point your...
2
by: Greg T | last post by:
Hi, I have a rather long form that I don't want people submitting unless they are absolutely sure they are ready. I figured the easiest way to prevent an accidental form submission by way of...
5
by: Don | last post by:
I have a need to submit a form, but don't need the user to click on a button. How do I do this? Is there some way, using JavaScript, to setup a <form> tag to do this? Thanks, Don ----==...
1
by: Richard Dixson | last post by:
I have code that calls document.myFormName.submit() to submit a form automatically via JavaScript. This works just fine. However, if there is a button (or other form field element) on the form...
1
by: Hello | last post by:
Scenario: A page creates a pop up and that pop up submits a form. Is there a way to detect whether the submitting was successful or not, so true/false could be passed to the parent window?
3
by: kgbalaji1980 | last post by:
Hi all, i want the jscript coding for more than one form in one page and submitting the same . ie one parent form and one append button when we click that button one child form will display...
18
by: NavinM | last post by:
I have a couple of forms that are misbehaving in FireFox, but work fine in IE. when i do submit( with submit button) a javascript function validates all of the fields entered, and stops the...
1
by: dittu | last post by:
How to close the popup window when submitting the form? I have a sample.jsp. In that page one button is there. when button pressed, open popup window contains one "text box" and one " submit...
6
by: phpnewbie26 | last post by:
This has been confusing me for a while. I don't understand why it isn't working. In my original coding, I have an action called submitted.php and this is what is looks like: <?php ...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.