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

multiple form destinations

P: n/a
Hello,

I was wondering if it is possible to create in one form 2 destination for
example

<form method="post" action="test.html">
<textarea name="content">
Test
</textarea>
<inbut button="submit" name="submit" value="submit">
</form>

Now I want a second button lets say submit2 and when it is clicked I want to
post to test2.html instead test.html.
Is that possible without an if else?

Thanks for advice
Chris
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
gokul wrote on 28 Nov 2003:
Yes you can do that.
Please follow the steps as follows:
Lets assume form name is myForm
function onSubmit_activat(sURL)
{
document.myForm.action=sURL;
document.myForm.submit();
You should use the forms and elements collections to make the script
compatible with more browsers:

document.forms['myForm'].elements['action'] = sURL;
document.forms['myForm'].submit();
}
<form method="post" name="myForm" >
You shouldn't omit the action attribute, even if you can guarantee
that the user will have JavaScript enabled - it's invalid HTML. If
you can't guarantee that JavaScript will be enabled, you shouldn't
really attempt this method at all, but instead find another way of
presenting your website.
<textarea name="content">
Test
</textarea>
<input type="button" name="submit" value="submit"
onClick="javascript:onSubmit_activat('test.html')" >


At the present moment, your script will probably fail here. The name
of the control is submit, which is also a Form method. Some browsers
will get confused by this. Never name a submit button, submit, or a
reset button, reset. In fact, don't use any names that could collide
with those used by the Form object (lookup the properties and methods
of the Form object in a JavaScript reference).

Furthermore, if you write valid HTML, there should never be a need to
use the JavaScript protocol specifier (it's only supposed to be used
in URIs anyway, which again is discouraged). Specify the language of
intrinsic events with the following META element (placed in the
document HEAD):

<META http-equiv="Content-Script-Type" content="text/javascript">

<snipped other control and original post>

Mike

And please don't top-post. :)

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #2

P: n/a
Michael Winter wrote:
gokul wrote on 28 Nov 2003:
Yes you can do that.
Please follow the steps as follows:
Lets assume form name is myForm
function onSubmit_activat(sURL)
{
document.myForm.action=sURL;
document.myForm.submit();


You should use the forms and elements collections to make the script
compatible with more browsers:

document.forms['myForm'].elements['action'] = sURL;


action isn't an element of the form, it's a property or attribute (<form
.... action="somepage.cgi" ...>), so the code originally provided is
correct.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #3

P: n/a
Grant Wagner wrote on 02 Dec 2003:
Michael Winter wrote:
gokul wrote on 28 Nov 2003:
> Yes you can do that.
> Please follow the steps as follows:
> Lets assume form name is myForm
> function onSubmit_activat(sURL)
> {
> document.myForm.action=sURL;
> document.myForm.submit();


You should use the forms and elements collections to make the
script compatible with more browsers:

document.forms['myForm'].elements['action'] = sURL;


action isn't an element of the form, it's a property or
attribute (<form ... action="somepage.cgi" ...>), so the code
originally provided is correct.


Sorry, I was thinking for some reason that it was a control in the
OP's form. I know it's an attribute, I think I just blindly altered
it to the collection syntax.

Mike

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.