submit form to different locations on Radio buttons toggle

Discussion in 'Javascript' started by sam, May 26, 2006.

  1. sam

    sam Guest

    Hi All,

    I have a form with 4 checkboxes and 4 text boxes and one submit button.
    The form should work such a way when I select a particular checkbox and
    give a url in text box, the form should get submitted to that url
    entered in the text box. Is this possible. I know to submit form by
    metioning the action attribute only. How do this with one button but
    submitting to different locations on different selection...Can any one
    help me proceed further. My form will look something like this.

    Thanks,
    Sam

    <html>
    <head>
    </head>
    <script>
    function submitme()
    {
    var form = document.forms['test_submit'];
    var selected = form.elements.chk;

    if (selected[0].checked)
    {
    var url = document.test_submit.text1.value;
    form.submit(url); // is this correct at all, I get an error
    }
    else if (selected[1].checked)
    {
    do something to submit the value entered in text box
    }
    else if (selected[2].checked)
    {
    do something to submit the value entered in text box
    }
    else if (selected[3].checked)
    {
    do something to submit the value entered in text box
    }
    }
    </script>
    <body>
    <div style="border:1px solid red; margin:auto; width: 750px; padding:
    20px;">
    <form name="test_submit" action="#" method="POST">
    <input type="checkbox" name="chk" value="rd1" /><input type="text"
    name="text1" />
    <br /><br />
    <input type="checkbox" name="chk" value="rd2" /><input type="text"
    name="text2" />
    <br /><br />
    <input type="checkbox" name="chk" value="rd2" /><input type="text"
    name="text3" />
    <br /><br />
    <input type="checkbox" name="chk" value="rd2" /><input type="text"
    name="text4" />
    <br /><br />
    <input type="submit" name="submit1" value="Submit to desired value"
    onclick="javascript:submitme();">
    </form>
    </div>
    </body>
    </html>
     
    sam, May 26, 2006
    #1
    1. Advertising

  2. sam

    Dag Sunde Guest

    "sam" <> skrev i melding
    news:...
    > Hi All,
    >
    > I have a form with 4 checkboxes and 4 text boxes and one submit button.
    > The form should work such a way when I select a particular checkbox and
    > give a url in text box, the form should get submitted to that url
    > entered in the text box. Is this possible. I know to submit form by
    > metioning the action attribute only. How do this with one button but
    > submitting to different locations on different selection...Can any one
    > help me proceed further. My form will look something like this.
    >
    > Thanks,
    > Sam
    >
    > <html>
    > <head>
    > </head>
    > <script>
    > function submitme()
    > {
    > var form = document.forms['test_submit'];
    > var selected = form.elements.chk;
    >
    > if (selected[0].checked)
    > {
    > var url = document.test_submit.text1.value;
    > form.submit(url); // is this correct at all, I get an error

    <snipped/>

    Try something like
    frm.action=url;

    instead, and terminate your onSubmit function with
    return true;

    --
    Dag.
     
    Dag Sunde, May 26, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    949
  2. Scott D Johnson
    Replies:
    1
    Views:
    1,083
    Scott D Johnson
    Sep 27, 2006
  3. Kevin Audleman
    Replies:
    2
    Views:
    86
  4. Dr. Leff
    Replies:
    3
    Views:
    302
    David Mark
    Oct 15, 2007
  5. Dr. Leff
    Replies:
    3
    Views:
    232
    David Mark
    Oct 15, 2007
Loading...

Share This Page