How Can I Get Drowp Down List Value on Next Page ?

saqib389saqib389 BeginnerLink Clerk
here is the code of

page1.php
<html>
<head>
<title>My Page</title>
</head>
<body>
<form name="myform" action="display.php">
<div align="center">
<select name="mydropdown">
<option value="color1">black</option>
<option value="color2">red</option>
<option value="color3">Orange</option>
</select>
</div>
</form>
</body>
</html>

now i want to display on DISPLAY.PHP
the value of that which user selected in dropdownlist
like user select red option. then on next page there shuld b display RED and also there shuld b display RED COLOR.......
can any one tell me how can i dot this ?

Comments

  • PythonPython Forum Leader The Royal RAM
    Ok sure,

    The way these works is that when the form is submitted it passes the value of the selected option to the forms action in this case display.php

    On display.php you can then access the value of the selected item using the lists name...

    Like this:

    [PHP]echo $_POST[mydropdown];[/PHP]

    If for example the option of red was chosen then the above would display the word "color2". Its shows that because that is the value of the red option on page1.php

    You could then do something like this:

    [PHP]switch($_POST[mydropdown)
    {
    case "color1":
    echo "Color is Black";
    break;

    case "color2":
    echo "Color is Red";
    break;

    case "color3":
    echo "Color is Orange";
    break;

    default:
    echo "No color selected";
    }
    [/PHP]

    Make sense?

    The Royal Ram

  • saqib389saqib389 Beginner Link Clerk
    ya i got it thnx buddy...
  • PythonPython Forum Leader The Royal RAM
    No problem :)
    Glad to help :)

    The Royal Ram

Sign In or Register to comment.