Passing selection box values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cherryst152
    New Member
    • Nov 2007
    • 16

    Passing selection box values

    So I'm taking two simple selection boxes (select...optio ns), the whole shabang.

    What I want to do is test the values in these when someone is to select them. My problem is i want a simple way, I'm thinking a php if statement where i can test this. Example is below. There is much more complexity to this problem, but this would get me moving in the correct path.

    [code=html]
    <select name="list"><op tion value="1">1<opt ion value="2">2</select>

    if (list.value == 1){
    echo "Hi";
    }
    [/code]

    I believe the value part is my main concern. I am trying to do a php form of javascript regular expression. My biggest question is how can i specify the text that is selected from a selection box and thus perform whatever actions i want after this??????
    Last edited by Atli; Nov 7 '07, 11:31 PM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi Cherry. Welcome to TSDN!

    If you are simply looking for a way to use the data from your form in your PHP code, I'd recommend check out this article..

    A simple example of what you are asking could look something like this:
    [code=php]
    <?php
    if(isset($_POST['list'])) {
    if($_POST['list'] == 1) {
    echo "You selected 1";
    }
    else if($_POST['list'] == 2) {
    echo "You selected 2";
    }
    else {
    echo "You selected something else";
    }
    }
    ?>

    <form action="?" method="POST">
    <select name="list">
    <option value="1">1</option>
    <option value="2">2</option>
    </select>
    <br /><input type="submit" />
    </form>
    [/code]

    Comment

    Working...