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

Thread: Checkboxes

  1. #1
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default Checkboxes

    Hey all..

    I have several checkboxes on a page. When a particular checkbox is clicked and the "next" button is clicked, I'd like the browser to point to a particular URL.

    How do I:

    1) Make it so only 1 check box is clicked at a time and/or check if more than 1 is selected and then promt user to only pick one.

    2) Go to a particular webpage based on the checkbox selected.

    Would I do this with JS, PHP, what?

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

    Default

    PHP, preferably. It can be done with JS, but it would be a bad idea, since non-JS users wouldn't be able to use it. If you only want one item selected, you actually want a radio button.
    Code:
    <?php
      error_reporting(E_ALL); // because headers always cause trouble.
      if(isset($_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>Redirect to Page</title>
      </head>
      <body>
        <form action="<?php print $_SERVER['PHP_SELF']; ?>" 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.clusty.com/">
              Clusty
            </label>
            <label>
              <input type="radio" name="url" value="http://www.twey.co.uk/">
              Twey
            </label>
          </div>
        </form>
      </body>
    </html>
    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!

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    This line would give an error:

    Code:
    header('Location: ' . $_POST['url']);
    So instead use this:

    Code:
    header('Location: ' . $_POST["url"]);
    Note: This is only for certain PHP configurations or something to that effect (read my post below).
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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

    Default

    What? No it wouldn't. And the double quotes would be a whole fraction of a millisecond slower
    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!

  5. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    That's wierd, I just tested it on two seperate installations. It worked fine with one (with the code you posted) but not with the other as it through up a parse error. I guess it just depends on the server config; so for that, just ignore my last post unless you have that problem as well.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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

    Default

    Hmm? I can't see where the parse error would come from... what was the exact message?
    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!

  7. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Ok, again, forget my post yet again. I figured out that I added something on the one that wasn't working that shouldn't have been there (I actually forgot a quote). Sorry for the confusion, and I will pay more attention next time (it's been a hell of a day with my daughter's birthday party and all).
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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

    Default

    Oh, congratulations to her. How old?
    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!

  9. #9
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    She turns 5 on the 17th. Getting so big and sassy (like her mother) .
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  10. #10
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Thanks for the help guys.

    But it's not working for me.
    Not matter which radio button I select and then click submit, it takes me to "/<"

    What could be causing this?

    I didn't change anything except adding a submit button.

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
  •