Jump to content

Get Drop Down Value of HTML in PHP


RaJiska

Recommended Posts

Hello,

 

I have a drop down menu, and I wish to know how to get the value selected in the drop down (made with HTML & CSS) into a PHP variable.

Here is how it looks like:

<html>
<body>
<form name="myform" action="" method="">
<div align="center">
<select name="mydropdown">
<option value="1h">1 Hour</option>
<option value="3h">3 Hours</option>
<option value="12h">12 Hours</option>
<option value="1d">1 Day</option>
<option value="3d">3 Days</option>
<option value="1w">1 Week</option>
<option value="2w">2 Weeks</option>
<option value="3w">3 Weeks</option>
<option value="1m">1 Month</option>
</select>
</div>
</form>
</body>
</html>

Then it should be get when this PHP button is pressed:

echo('<input type="submit" name="test" value="Hello My Name is Bob"/>');

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/283511-get-drop-down-value-of-html-in-php/
Share on other sites

As you haven't set the forms submit mehtod (method="")

<form name="myform" action="" method="">

and you have named your drop down menu as mydropdown

<select name="mydropdown"> 

When the form has been submitted, then you'll get the selected value using $_GET['mydropdown']. If you set the forms submit method to post (method="post") you'd use $_POST['mydropdown']

Yep, thanks, it worked with $_POST.

Alos, I might have to ask another question, it's here:

$test1 = 1;
$test2 = 1;
if ($ip == $test1 || $test2)
{
?>
        <br><input type="submit" value="Click test" />
<?php
}
echo "IP: $ip";
?>

The problem is with: if ($ip == $test1 || $test2) (that is not normal since my IP is not '1' or '1'), I can see the button, but with: if ($ip == $test1) I can (that should be normal since my IP is not 1).

ThankS.

Yep, thanks, it worked with $_POST.

Alos, I might have to ask another question, it's here:

$test1 = 1;
$test2 = 1;
if ($ip == $test1 || $test2)
{
?>
        <br><input type="submit" value="Click test" />
<?php
}
echo "IP: $ip";
?>

The problem is with: if ($ip == $test1 || $test2) (that is not normal since my IP is not '1' or '1'), I can see the button, but with: if ($ip == $test1) I can (that should be normal since my IP is not 1).

 

ThankS.

 

Try this

if ($ip == $test1 || $ip == $test2)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.