By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

document.form.submit() question

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
"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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.