Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Submit a "different" form onClick

    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:

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

    Yet apparently, no dice. Any help here guys?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,210
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    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?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,210
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    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:
    Code:
    <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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •