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

Thread: Forms

  1. #1
    Join Date
    Oct 2007
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Forms

    I have two radio buttons, as I want them to hold different information. Both will hold two seperate links and I want the user to select one then hit a GO button. As they hit the GO button, I want them to go to whatever link that was attached to the radio button that is selected. Any suggestions?
    Last edited by pssparkman; 01-03-2008 at 09:30 AM.

  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

    Using HTML alone, you cannot. There are probably various ways. Here's one which requires javascript:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    </head>
    <body>
    <form action="#" onsubmit="for (var e=this.elements, i = e.length-1; i > -1; --i)
    if(e[i].name=='url'&amp;&amp;e[i].checked)
    window.location=e[i].value;
    return false;">
    <div>
    <input type="radio" name="url" value="http://www.google.com/">Google<br>
    <input type="radio" name="url" value="http://www.dynamicdrive.com/">Dynamic Drive<br>
    <input type="submit" value="Go!">
    </div>
    </form>
    </body>
    </html>
    - John
    ________________________

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

  3. #3
    Join Date
    Oct 2007
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It worked, Thank You. Is there a way to get them to open up in a new windown or tab when submitted. I have tried to set the form to do it, but it doesn't want to.

    Also I another issue that is about the same as the previous one, but one is a link and the other is a form within that I need to be able to run when its radio button is selected and go is hit.
    Last edited by pssparkman; 01-03-2008 at 08:32 PM.

  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

    I'm not that clear on what you are talking about, but see:

    http://www.dynamicdrive.com/forums/s...ad.php?t=26289

    particularly post #3 in that thread. It might be close to what you are saying. When you say a form within, within what?
    - John
    ________________________

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

  5. #5
    Join Date
    Oct 2007
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The form you game me is a form, but one of the radio buttons needs to hold a form of its own. So when that radio button is selected and the submit button is hit. The form that is attached to that radio button will execute. Does that make more sense? Sorry it wasn't clear enough before.

  6. #6
    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

    Something like so? The 'inner' form isn't really inner, and is just the most basic sort of form. It could be a very complex form though:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    </head>
    <body>
    <form action="#" name="days">
    <div>
    Days: <input type="text" name="days" value="24">
    </div>
    </form>
    <form action="#" onsubmit="return false;">
    <div>
    <input type="radio" name="act" value="url::http://www.google.com/">Google<br>
    <input type="radio" name="act" value="frm::days">Execute Days<br>
    <input type="submit" value="Go!" 
    onclick="for (var e=this.form.elements, i = e.length-1; i > -1; --i)
    if(e[i].name=='act'&amp;&amp;e[i].checked)
    if(e[i].value.split('::')[0]=='url')
    window.open(e[i].value.split('::')[1],'_blank','top=100, left=250, width=600, height=400, location, resizable');
    else if(e[i].value.split('::')[0]=='frm')
    document.forms[e[i].value.split('::')[1]].submit();">
    </div>
    </form>
    </body>
    </html>
    Notes: Once again, javascript is required. If you need more fine tuning, it would probably be easier for me to know exactly what you want the 'inner' form to do.
    - John
    ________________________

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

  7. #7
    Join Date
    Oct 2007
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I know just looking at it, it can be complicated to understand what is going on in it. But as a radio button is selected (two radios max) and then the submit button is clicked. If this particular radio is seleceted I need it to execute this form:

    PHP Code:
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <
    input type="hidden" name="cmd" value="_xclick">
    <
    input type="hidden" name="business" value="paypal@squadserver.com">
    <
    input type="hidden" name="undefined_quantity" value="1">
    <
    input type="hidden" name="item_name" value="TeamWork Gaming Server Payment">
    <
    input type="hidden" name="item_number" value="QP">
    <
    input type="hidden" name="page_style" value="SquadServer">
    <
    input type="hidden" name="no_shipping" value="1">
    <
    input type="hidden" name="return" value="http://www.squadserver.com/paypal/quickpay.html">
    <
    input type="hidden" name="cn" value="Payment Instructions">
    <
    input type="hidden" name="currency_code" value="USD">
    <
    input type="hidden" name="bn" value="PP-BuyNowBF">
    <
    input type="submit" name="Submit" id="submit2" value="Donations" width="160"/>
    </
    form
    Alone as a form on it own, it does the job. But I have serveral things that can be donated to, so I want the user to select what they want to donate to from the radios. The other donate radios are using web address, as this is too with extra info to fill in the form being used.

    I hope it makes sense.

  8. #8
    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

    As I said, it doesn't matter how complex the form is. But the form should have a name, so by substituting your form for the simple form and giving it a name, we can make it work with the code given:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    </head>
    <body>
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="pp1">
    <div>
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="paypal@squadserver.com">
    <input type="hidden" name="undefined_quantity" value="1">
    <input type="hidden" name="item_name" value="TeamWork Gaming Server Payment">
    <input type="hidden" name="item_number" value="QP">
    <input type="hidden" name="page_style" value="SquadServer">
    <input type="hidden" name="no_shipping" value="1">
    <input type="hidden" name="return" value="http://www.squadserver.com/paypal/quickpay.html">
    <input type="hidden" name="cn" value="Payment Instructions">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="bn" value="PP-BuyNowBF">
    <input type="submit" name="Submit" id="submit2" value="Donations" width="160"/>
    </div>
    </form> 
    <form action="#" onsubmit="return false;">
    <div>
    <input type="radio" name="act" value="url::http://www.google.com/">Google<br>
    <input type="radio" name="act" value="frm::pp1">Make TeamWork Gaming Server Payment<br>
    <input type="submit" value="Go!" 
    onclick="for (var e=this.form.elements, i = e.length-1; i > -1; --i)
    if(e[i].name=='act'&amp;&amp;e[i].checked)
    if(e[i].value.split('::')[0]=='url')
    window.open(e[i].value.split('::')[1],'_blank','top=100, left=250, width=600, height=400, location, resizable');
    else if(e[i].value.split('::')[0]=='frm')
    document.forms[e[i].value.split('::')[1]].submit();">
    </div>
    </form>
    </body>
    </html>
    Incidentally, if you want this PayPal form to post open to a new window, just set its target to _blank:

    Code:
    <form target="_blank" action="https://www.paypal.com/cgi-bin/webscr" method="post" name="pp1">
    - John
    ________________________

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

  9. #9
    Join Date
    Oct 2007
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks it works perfect. I know there had to be a way it could be done, both ways.

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Or using a server-side language (here PHP):
    Code:
    <?php if(@$_POST['url'])
      header('Location: ' . $_POST['url']); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
      <head>
        <title>Document sans Titre</title>
      </head>
      <body>
        <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
          <div>
            <label>
              <input type="radio" name="url" value="http://www.google.com/">
              Google
            </label>
            <label>
              <input type="radio" name="url" value="http://www.yahoo.com/">
              Yahoo!
            </label>
            <label>
              <input type="radio" name="url" value="http://www.example.com/">
              Example
            </label>
          </div>
        </form>
      </body>
    </html>
    This way is better, although it's only possible if you have a scripting-enabled server.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •