Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Form POST redirect based on radio button selected

  1. #1
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Form POST redirect based on radio button selected

    I have three options on a form. When the form is posted the user is redirected to a thank you page.

    <input type="hidden" id="U386058799TNT63" name="redirect" value="http://www.estateagentsespana.com/regtku.htm">

    What I would like to be able to do is change the redirect depending on which radio button was selected. E.g. if option 1 was selected redirect to regtku1.htm, if option 2 was selected redirect to regtku2.htm
    Cheers
    Billy

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Give this a shot:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function usePage(frm,nm){
    for (var i_tem = 0, bobs=frm.elements; i_tem < bobs.length; i_tem++)
    if(bobs[i_tem].name==nm&&bobs[i_tem].checked)
    frm.action=bobs[i_tem].value;
    }
    </script>
    </head>
    <body>
    <div>
    <form action="#" method="post" onsubmit="usePage(this, 'bob');">
    <input type="radio" name="bob" value="regtku1.htm">
    <input type="radio" name="bob" value="regtku2.htm">
    <input type="radio" name="bob" value="regtku3.htm">
    <input type="submit" value="Go">
    </form>
    </div>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Thanks, John.

    The code supplied works fine - only problem is I was using onsubmit to check form input (onsubmit = "return checktheform()").

    Is it possible to combine the input verification with the call to the redirect function?
    Cheers
    Billy

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    onsubmit = "usePage(this, 'bob');return checktheform();"
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Works brilliantly. Thanks, John
    Cheers
    Billy

  6. #6
    Join Date
    Jul 2005
    Posts
    101
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Everything worked fine on my machine but when I uploaded to the server I get this message:

    Method Not Allowed
    The requested method POST is not allowed for the URL /regtku1.htm.

    Apache/1.3.37 Server at site Port 80

    The address bar showed the full URL. Is there something else I need to do?
    Cheers
    Billy

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I may have misunderstood your requirements. I assumed that the redirect should be the action of the form, but perhaps not. Perhaps it needs to follow the format you laid out in your first post:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function usePage(frm,nm){
    for (var i_tem = 0, bobs=frm.elements; i_tem < bobs.length; i_tem++)
    if(bobs[i_tem].name==nm&&bobs[i_tem].checked)
    frm.redirect.value='http://www.estateagentsespana.com/'+bobs[i_tem].value;
    }
    </script>
    </head>
    <body>
    <div>
    <form action="#" method="post" onsubmit="usePage(this, 'bob');return checktheform();">
    <input type="hidden" id="U386058799TNT63" name="redirect" value="http://www.estateagentsespana.com/regtku.htm">
    <input type="radio" name="bob" value="regtku1.htm">
    <input type="radio" name="bob" value="regtku2.htm">
    <input type="radio" name="bob" value="regtku3.htm">
    <input type="submit" value="Go">
    </form>
    </div>
    </body>
    </html>
    Notes: You may need to adapt this further to suit your actual requirements. I don't know what the action should be, there is nothing that you've told me that would indicate that with any certainty. Also, I am only using the post method because you mentioned posting the form. And, I don't have a clue as to what checktheform(); does specifically.

    If you have an example of any form for this that actually works live (even one that only redirects to one of the pages), I may be able to be more helpful should you require it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Apr 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi John,

    Later that decade ...

    I accept your original post is now very old and I apologize but I cannot find a solution to my problem

    I have used your example above to good effect thank you. Its very much appreciated.

    But for the life of me it will not work in ie7 or safari .. any clues ?

    Always online.

    Richard

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    It might have to be live to work in some browsers. Problems in those browsers might be due to other factors.

    If making it live doesn't solve the problem. because it is an old thread and because your situation might be different than that of the original person's in this thread, please post a link to a page on your site that demonstrates the problem. Also include in your post as detailed an explanation as possible of your current objectives with this code and what it doesn't do in the problem browsers, and what I have to do to see it misbehave.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Apr 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi John,

    I'm very thankful for your time... cheers.

    The URL is Live and still misbehaving in IE7

    http://c26.futurestudios.info/contact-us/

    If you visit using say firefox and post the form with a radio button selected you are redirected to a thank you page bespoke to the radio button you selected .. i.e. type of enquiry.

    I cant seem to get this to work in IE7.

    It seems fine in all others ?

    Again thanks in advance for any assistance.

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
  •