SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jul 2007
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I submit form with JS - dynamic form names?

    Greetings,

    I have a site that has dynamically generated forms with multiple submit buttons. My forms are like this, created using PHP and inserts different user names on the same page:

    <form action="step2.php" name="john" onsubmit="return SubmitForm(john);" method="post">
    ...
    </form><a href='javascript:{}' onclick='return SubmitForm(john);'>Submit</a>

    <form action="step2.php" name="hams" onsubmit="return SubmitForm(hams);" method="post">
    ...
    </form><a href='javascript:{}' onclick='return SubmitForm(hams);'>Submit</a>

    <form action="step2.php" name="toob" onsubmit="return SubmitForm(toob);" method="post">
    ...
    </form><a href='javascript:{}' onclick='return SubmitForm(toob);'>Submit</a>


    People click a link and the form submits via:
    function SubmitForm(member)
    {
    document.member.submit();
    }

    The member name goes into the JavaScript to variable: member.

    The Problem: is when this JS tries to submit the form called "john" for example, it searches for a form called "member" instead and it fails. Is there any way to fix this? I'm sure there is a way to deal with this kind of issue but I don't know it yet.

    Thanks

  2. #2
    SitePoint Addict
    Join Date
    Jul 2007
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, nevermind I got it. Thanks for looking anyways.

    Strange how I monkey around with it for a few hours, create a post here and literally 5 minutes later find the solution...

    document.forms[member].submit();


Bookmarks

Posting Permissions

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