I have a select tag with different values as shown below. I want to send the selected value to a PHP page as a POST variable or any other way. Is this possible?
<select id="city" name="city" align="left">
<option value="Pune">Pune</option>
<option value="Bhopal">Bhopal</option>
<option value="Mumbai">Mumbai</option>
<option value="New Delhi">New Delhi</option>
</select>
Yes, and it's very simple. You have to use the from tag : http://www.w3schools.com/html/html_forms.asp and learn a little of PHP and HTML basic interaction
<form action = 'myPage.php' method = 'post'>
<select id="city" name="city" align="left">
<option value="Pune">Pune</option>
<option value="Bhopal">Bhopal</option>
<option value="Mumbai">Mumbai</option>
<option value="New Delhi">New Delhi</option>
</select>
<input type = 'submit' name = 'send' value = 'send'/>
</form>
(I also added a button son send data)
in myPage.php :
<?php
if(isset($_POST['city'])){
echo isset($_POST['city'];
}
?>
Put your select inside a form. Give the form an action
that is a php file. give it the method
of post
and include a <input type="submit" value="Submit">
inside the form as well.
Then, in your php file you will access the $_POST
array
echo $_POST['city'];
If you'd like to submit it without the button, you'll need to use javascipt's onChange event.