Results 1 to 3 of 3

Thread: Select a text from selectbox

  1. #1
    Join Date
    Jul 2012
    Posts
    197
    Thanks
    55
    Thanked 3 Times in 3 Posts

    Default Select a text from selectbox

    Can any body help for the following simple issue

    I have a select box as following

    Code:
    <select name="gender">
    <option value="0">  Select </option>
    <option value="1">    Male   </option>
    <option value="2">  Female </option>
    </select>
    I need php code to check the the selected one is Male

    It should be like
    Code:
    if (selected one is Male) {
    echo "print";
    }

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    2,009
    Thanks
    16
    Thanked 315 Times in 313 Posts
    Blog Entries
    13

    Default

    Something like;
    HTML
    Code:
    <form action="process.php" method="post">
    <select name="gender">
    <option value="0">  Select </option>
    <option value="1">    Male   </option>
    <option value="2">  Female </option>
    </select>
    <input name="process" type="submit" value="Submit" />
    </form>
    process.php
    Code:
    $selected = $_POST['gender'];
    if ($selected == 0) {
    echo 'No gender selected';
    } else if ($selected == 1) {
    echo 'Male option selected';
    } else if ($selected == 2) {
    echo 'Female option selected';
    }
    Because php is run server-side, the form would need to be submitted and actioned on the server before the options can be processed.

    If you do not want to submit the form and instead want to perform an action "live" in the browser (eg- you want to populate the next question based on a users previous selection) you're probably looking at "chained selects" using JavaScript. Here's the DD script for that: http://www.dynamicdrive.com/dynamici...ects/index.htm
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  3. The Following User Says Thank You to Beverleyh For This Useful Post:

    letom (02-23-2013)

  4. #3
    Join Date
    Jul 2012
    Posts
    197
    Thanks
    55
    Thanked 3 Times in 3 Posts

    Default

    @Beverleyh
    Once again Thanks fr ur message
    May be an Experienced programmer can say what i am looking for
    If any assistance needed i will post

Similar Threads

  1. No select text script
    By jscheuer1 in forum Bug reports
    Replies: 3
    Last Post: 10-08-2006, 04:53 AM
  2. The No select text script
    By dragonbook in forum Dynamic Drive scripts help
    Replies: 12
    Last Post: 10-10-2005, 07:13 PM
  3. No select-text script help
    By LordVoldemort in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 08-10-2005, 07:10 PM
  4. no select text script
    By wilfredong138 in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 06-01-2005, 09:14 PM
  5. no select text script
    By wilfredong138 in forum HTML
    Replies: 0
    Last Post: 06-01-2005, 10:44 AM

Tags for this Thread

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
  •