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

Thread: form redirect

  1. #1
    Join Date
    Jul 2008
    Posts
    81
    Thanks
    38
    Thanked 2 Times in 2 Posts

    Default form redirect

    Hi I have a simple login (user and password) form.
    This form also includes this multiple menu:
    PHP Code:
    <select name="selectgrade" id="selectgrade">
            <
    option>A</option>
            <
    option>B</option>
            <
    option>C</option>
            <
    option>D</option>
          </
    select
    How can I do that each option will redirect the user to another url?

    Thanks
    Last edited by lord22; 08-05-2008 at 10:28 AM.

  2. #2
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Use the onclick attribute of each <option> to set window.location.href.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  3. #3
    Join Date
    Jul 2008
    Posts
    81
    Thanks
    38
    Thanked 2 Times in 2 Posts

    Default

    but I should redirect the user only when he clicked the button (and he passes the validation..)

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code:
    <select name="selectgrade" id="selectgrade" onchange="window.location.href=this['options'][this['selectedIndex']]['value']">
    	<option></option>
    	<option value="http://www.google.ca/">A</option>
    	<option value="http://www.yahoo.com/">B</option>
    	<option>C</option>
    	<option>D</option>
    </select>
    - Mike

  5. The Following User Says Thank You to mburt For This Useful Post:

    lord22 (08-06-2008)

  6. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Actually, after re-reading your post, why don't you just do this with $_POST["selectgrade"] on the validation page? That is, assuming you are using a form.
    - Mike

  7. #6
    Join Date
    Jul 2008
    Posts
    81
    Thanks
    38
    Thanked 2 Times in 2 Posts

    Default

    This is exatcly what I've tried to do, I just don't know how to get the information from the select menu

  8. #7
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    This is working:
    PHP Code:
    <?php echo $_POST['selectgrade']; ?>
    <form method="post" action="<?php $_SERVER['PHP_SELF']?>">
    <select name="selectgrade" id="selectgrade">
            <option>A</option>
            <option>B</option>
            <option>C</option>
            <option>D</option>
          </select> 
          <input type="submit" value="Submit">
          </form>
    Now, what's the problem on it? What validation are you expecting?

    Hope that keeps you going.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  9. The Following User Says Thank You to rangana For This Useful Post:

    lord22 (08-06-2008)

  10. #8
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Yeah, sorry I didn't look at the "PHP" at the top of the page. I was trying to answer a JavaScript question you didn't have.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  11. The Following User Says Thank You to Jesdisciple For This Useful Post:

    lord22 (08-06-2008)

  12. #9
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    The $_POST data will echo the value of the selected index, so you need a value tag in each option.

    PHP Code:
    <?php echo $_POST['selectgrade']; ?> 
    <form method="post" action="<?php $_SERVER['PHP_SELF']?>"> 
    <select name="selectgrade" id="selectgrade"> 
            <option value="option_a">A</option> 
            <option value="option_b">B</option> 
            <option value="option_c">C</option> 
            <option value="option_d">D</option> 
          </select>  
          <input type="submit" value="Submit"> 
          </form>

  13. The Following User Says Thank You to motormichael12 For This Useful Post:

    lord22 (08-06-2008)

  14. #10
    Join Date
    Jul 2008
    Posts
    81
    Thanks
    38
    Thanked 2 Times in 2 Posts

    Default

    Hi

    can someone tell what's wrong in here:
    PHP Code:
    $sql="INSERT INTO grades (selectgrade)
    VALUES
    ('
    $_POST['selectgrade']')"
    ?

    It wrote me that there is some syntax error there.

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
  •