Connecting Tech Pros Worldwide Forums | Help | Site Map

multiple form destinations

Christian
Guest
 
Posts: n/a
#1: Jul 20 '05
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



Michael Winter
Guest
 
Posts: n/a
#2: Jul 20 '05

re: multiple form destinations


gokul wrote on 28 Nov 2003:
[color=blue]
> 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();[/color]

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();
[color=blue]
> }
>
>
> <form method="post" name="myForm" >[/color]

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.
[color=blue]
> <textarea name="content">
> Test
> </textarea>
> <input type="button" name="submit" value="submit"
> onClick="javascript:onSubmit_activat('test.html')" >[/color]

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.Winter@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Grant Wagner
Guest
 
Posts: n/a
#3: Jul 20 '05

re: multiple form destinations


Michael Winter wrote:
[color=blue]
> gokul wrote on 28 Nov 2003:
>[color=green]
> > 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();[/color]
>
> You should use the forms and elements collections to make the script
> compatible with more browsers:
>
> document.forms['myForm'].elements['action'] = sURL;[/color]

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 <gwagner@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


Michael Winter
Guest
 
Posts: n/a
#4: Jul 20 '05

re: multiple form destinations


Grant Wagner wrote on 02 Dec 2003:
[color=blue]
> Michael Winter wrote:
>[color=green]
>> gokul wrote on 28 Nov 2003:
>>[color=darkred]
>> > 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();[/color]
>>
>> You should use the forms and elements collections to make the
>> script compatible with more browsers:
>>
>> document.forms['myForm'].elements['action'] = sURL;[/color]
>
> 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.[/color]

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.Winter@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Closed Thread