Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass correct html select value to $_POST php

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']

?

like image 237
ganjan Avatar asked Dec 13 '10 01:12

ganjan


People also ask

How do you get the selected value of dropdown in PHP with submit?

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 ).

How do I get the value of a select tag?

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).

How do you get the selected value of dropdown in PHP without submit on same page?

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.

How do I select a dropdown value in HTML?

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.


1 Answers

Add the name tag...

<select id="select" name="select" size="2 ">
like image 198
Ilyssis Avatar answered Oct 03 '22 22:10

Ilyssis