473,491 Members | 3,350 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

document.form.submit() question

Is there a way to use 'document.form.submit()' to submit a form to a url
other than that specified in the Form element?

--
Ed Jay (remove M to respond by email)
Dec 28 '05 #1
8 17845
"Ed Jay" <ed***@aes-intl.com> wrote in message
news:7b********************************@4ax.com...
Is there a way to use 'document.form.submit()' to submit a form to a url
other than that specified in the Form element?

--
Ed Jay (remove M to respond by email)


Yes. Change the form's "action=" value.

Dec 28 '05 #2
"McKirahan" <Ne**@McKirahan.com> wrote:
"Ed Jay" <ed***@aes-intl.com> wrote in message
news:7b********************************@4ax.com.. .
Is there a way to use 'document.form.submit()' to submit a form to a url
other than that specified in the Form element?

--
Ed Jay (remove M to respond by email)


Yes. Change the form's "action=" value.

Please elaborate.

I presume you mean something like document.form.???=new-url? Is this a
'permanent' change, i.e., do I have to reinitialize the page to return to
the original action?

--
Ed Jay (remove M to respond by email)
Dec 28 '05 #3
Ed Jay <ed***@aes-intl.com> wrote:
"McKirahan" <Ne**@McKirahan.com> wrote:
"Ed Jay" <ed***@aes-intl.com> wrote in message
news:7b********************************@4ax.com. ..
Is there a way to use 'document.form.submit()' to submit a form to a url
other than that specified in the Form element?

--
Ed Jay (remove M to respond by email)


Yes. Change the form's "action=" value.

Please elaborate.

I presume you mean something like document.form.???=new-url? Is this a
'permanent' change, i.e., do I have to reinitialize the page to return to
the original action?


Never mind. :-)

document.form.action = "new url" works and isn't permanent.

Thanks. (I was about to try rewriting the entire Form element with
innerHTML, but the outcome is only temporarily useful.)

--
Ed Jay (remove M to respond by email)
Dec 28 '05 #4
Lee <RE**************@cox.net> wrote:
Ed Jay said:

Is there a way to use 'document.form.submit()' to submit a form to a url
other than that specified in the Form element?


No, but you can change the URL specified in the Form object:
document.form.action=myNewUrl;
document.form.submit();

But you should consider using the onSubmit handler, instead of
the submit() method.


Thanks, Lee. I'm using onSubmit to call a preliminary validation script
and then submit() to actually submit the form.

I have a multi-page server-side app with the last page a report. I want to
be able to edit an earlier page and resubmit the edited data directly to
the last page; hence...

--
Ed Jay (remove M to respond by email)
Dec 28 '05 #5
Lee <RE**************@cox.net> wrote:
Ed Jay said:
Thanks, Lee. I'm using onSubmit to call a preliminary validation script
and then submit() to actually submit the form.


Don't do that.
If you want to actually submit the form, have the onsubmit handler
return true. If you don't want it to submit, return false.

<form action="whatever" onsubmit="return myValidation(this)">


I respect your advice, but please 'splain me why it's a bad idea to use
submit().

--
Ed Jay (remove M to respond by email)
Dec 28 '05 #6
Ed Jay said the following on 12/28/2005 5:48 PM:
Lee <RE**************@cox.net> wrote:

Ed Jay said:

Thanks, Lee. I'm using onSubmit to call a preliminary validation script
and then submit() to actually submit the form.


Don't do that.
If you want to actually submit the form, have the onsubmit handler
return true. If you don't want it to submit, return false.

<form action="whatever" onsubmit="return myValidation(this)">

I respect your advice, but please 'splain me why it's a bad idea to use
submit().


Disable javascript and then try to document.formName.submit().

At least by using the onSubmit, you leave the form useable by nonJS
browsers.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 28 '05 #7
Lee <RE**************@cox.net> wrote:
Ed Jay said:

Lee <RE**************@cox.net> wrote:
Ed Jay said:

Thanks, Lee. I'm using onSubmit to call a preliminary validation script
and then submit() to actually submit the form.

Don't do that.
If you want to actually submit the form, have the onsubmit handler
return true. If you don't want it to submit, return false.

<form action="whatever" onsubmit="return myValidation(this)">
I respect your advice, but please 'splain me why it's a bad idea to use
submit().


The simple answer is that it's simpler. The browser is already in
the process of submitting the form. It's just waiting for the onSubmit
handler to give it permission to proceed by returning anything except
false. Why go to the extra step of invoking the submit() method?


Understood. Of course, one could argue that as you're already in a js
routine validating or whatever, it's just as simple to finish in the js.
:-)
A more complete answer includes considerations of users who don't
have Javascript enabled, the chance that some browsers will be
confused by having submit() invoked while they're already in the
process of submitting the form, and the fact that the submit()
method is frequently accidentally clobbered by adding a form
element named "submit".


Yes, you're both 100% correct in this regard. That said, my visitors are
clients using the application as a paid-for service. I require that js be
enabled to take advantage of the service. If they don't want to do that
because they think it makes their system more secure or it blocks popups,
or whatever, we'll be supplying them with dedicated Opera or Firefox with
custom ini files in which js will be enabled.

Certainly, though, for generic web-based application, I agree...use js
sparingly.

Thanks much for the comments and explanation.

--
Ed Jay (remove M to respond by email)
Dec 29 '05 #8
Randy Webb <Hi************@aol.com> wrote:
Ed Jay said the following on 12/28/2005 5:48 PM:
Lee <RE**************@cox.net> wrote:

Ed Jay said:
Thanks, Lee. I'm using onSubmit to call a preliminary validation script
and then submit() to actually submit the form.

Don't do that.
If you want to actually submit the form, have the onsubmit handler
return true. If you don't want it to submit, return false.

<form action="whatever" onsubmit="return myValidation(this)">

I respect your advice, but please 'splain me why it's a bad idea to use
submit().


Disable javascript and then try to document.formName.submit().

At least by using the onSubmit, you leave the form useable by nonJS
browsers.


Understood. Thank you.

--
Ed Jay (remove M to respond by email)
Dec 29 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4519
by: Varun | last post by:
Hi There, I have a form("myRequest.asp") and the values from it are retrieved into the page ("output_Print.asp") on which I have two buttons('Save As Complete' and 'Save As Incomplete'). When the...
14
14107
by: Chris | last post by:
Heres my problem: <a href="javascript:void(document.buysell.submit())" target="_parent" onMouseOver="MM_swapImage('members','','images/membersf2.gif',1)" onMouseOut="MM_swapImgRestore()"><img...
2
6135
by: Miles Davenport | last post by:
My Javascript is rather rusty :( ... and I need to do change some form values, in the folowing way: (1). I have the following a href (wrapped in PHP), which calls processForm. ==== <input...
6
3672
by: skubik | last post by:
Hi everyone. I'm attempting to write a Javascript that will create a form within a brand-new document in a specific frame of a frameset. The problem is that I can create the form and input...
4
1600
by: jiing.deng | last post by:
I want to transfer a value "re1" to ldapDeleteUserExec.php The "alert(document.ha)" appears a dialog and shows "undefined." The "alert(document)" shows "object" But there seems some problem:...
5
33858
by: terence.parker | last post by:
I have a PHP application which I wrote last year - and the JavaScript worked fine then. For some reason, now it doesn't - neither on IE nor Firefox. Has something changed? When I click on my...
3
9239
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to...
23
6539
by: vunet | last post by:
It is recommended by some sources I found to create IFrames in IE using document.createElement('<iframe src="#">') instead of document.createElement('iframe'). Why and what browser versions to...
2
3099
by: ChrisLA | last post by:
Hi; I've seen lots of discussion & disagreement on this issue, so any good explanation would be appreciated. Some people seem to think that "document.GetElementByID("MyName").submit(); should...
0
7118
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7192
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.