...

View Full Version : Submit a "different" form onClick



sheppardzwc
08-21-2010, 02:11 AM
Hi everyone,

Been struggling with this one all day - writing a vBulletin mod and am having trouble submitting a form. Yes, yes, I know, you submit forms with HTML, but a form instance is created before my form instance - something like:

<form name="main_form" etc>
<form name="my_form" etc>
<input button>
<input submit>
</form>

So I said, well, why not just do this:


<input type="submit" value="Order" onClick="document.my_form.submit()" /></form>


Yet apparently, no dice. Any help here guys?

Old Pedant
08-21-2010, 02:37 AM
HTML does *NOT* allow *NESTED* <form>s!!!!

You'll never get it to work with the <form>s as you showed.

You can have multiple <form>s on a page, but the second <form> *MUST* appear after the </form> of the first one, etc.

sheppardzwc
08-21-2010, 02:52 AM
HTML does *NOT* allow *NESTED* <form>s!!!!

You'll never get it to work with the <form>s as you showed.

You can have multiple <form>s on a page, but the second <form> *MUST* appear after the </form> of the first one, etc.

Damn - any alternatives you could suggest?

Old Pedant
08-22-2010, 02:54 AM
I just suggested one: Put your second <form> *AFTER* your first one.

Period.

If the fields of the two forms need to be intermixed on the page, then you *could* do it like this:


<form name="ONE">
<input name="ONE_name" />
<input id="TWO_name" onchange="document.TWO[this.id].value=this.value;" />
<input name="ONE_email" />
<input id="TWO_email" onchange="document.TWO[this.id].value=this.value;" />
<input type="button" id="TWO_submit" onclick="document.TWO.submit();"/>
... more fields for ONE ...
</form>
<form name="TWO" action="somethingElse.xxx">
<input type="hidden" name="TWO_name" />
<input type="hidden" name="TWO_email" />
</form>

But of course that only works if the user does not disable JavaScript.

Notice that the fields in ONE that are really meant to be part of TWO do *NOT* have names. They only have id's. Fields without names are *not* sent on to the form's action url.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum