www.webdeveloper.com
Results 1 to 2 of 2

Thread: validate a drop down menu

  1. #1
    Join Date
    Apr 2006
    Posts
    58

    validate a drop down menu

    i am having trouble validating my drop down menu when the method of the form which it is in is "post".
    my code is:
    <form action="add.php" method="post">
    <?php
    $letter = array (1=> 'a','b','c','d','e','f' );
    echo '<select name="type">';
    echo '<option value="none"> - Choose - </option>';
    foreach($letter as $value1){
    echo "<option value=\"$value1\">$value1</option>\n";
    }
    echo '</select>';
    ?>
    </form>

    now i want to validate this drop down menu so that if it shows ' - Choose -' when the form is submitted that there will be an error message saying 'please select a value'. can anyone help me with trying to validate this drop down?

  2. #2
    Join Date
    Jun 2004
    Location
    4846′36″ N 910′48″ E
    Posts
    3,747
    PHP 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">
            <style type="text/css">
            
            </style>
        </head>
        <body>
    <?php
    if(!empty($_POST['type'])){
        echo 
    "<p>You choose: ".$_POST['type']."</p>";
    }else{
        echo 
    "<p>please select a value</p>";
    }
    ?>
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <?php
            $letter 
    = array (1=> 'a','b','c','d','e','f' );
            echo 
    '<select name="type">';
            echo 
    '<option> - Choose - </option>';
            foreach(
    $letter as $value1){
            echo 
    "<option value=\"$value1\">$value1</option>\n";
            }
            echo 
    '</select>';
            
    ?>
    <input type="submit" value="submit">
    </form>
        </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles