I have tried html like this:
<form method="post">
<select id="select" size="2 ">
<option value="3">test</option>
<option value="4">test2</option>
</select>
<button type="submit" value="execute">
</form>
How do I get a 3 or 4 value in the post array
$_POST['select']
?
Use the <select> element to create a dropdown list. Use the multiple attribute to create a list that allows multiple selections. Use $_POST to get the selected value of the select element if the form method is POST (or $_GET if the form method is GET ).
To get the value of a select or dropdown in HTML using pure JavaScript, first we get the select tag, in this case by id, and then we get the selected value through the selectedIndex property. The value "en" will be printed on the console (Ctrl + Shift + J to open the console).
The only way you can get this code into PHP is by submitting the page. What you can do however is use javascript to get the value - and then fire off an AJAX request to a php script passing the selected value and then deal with the results, e.g.
The select tag in HTML is used to create a dropdown list of options that can be selected. The option tag contains the value that would be used when selected. The default value of the select element can be set by using the 'selected' attribute on the required option. This is a boolean attribute.
Add the name tag...
<select id="select" name="select" size="2 ">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With