answersLogoWhite

0

How do you retrieve an HTML option value using PHP?

Updated: 8/17/2019
User Avatar

Wiki User

14y ago

Best Answer

You will have to build a form for this:


Put the form elements inside this and add a submit button (). Once the user clicks the submit button, all selected and entered values are sent to the file "eval.php" using the get-method, i.e. they are entered into the URL. You may alternatively use the post-method (method="post"), which sends the values "invisibly".

In your php script you can now access the variables using the $_GET array. This array is filled with the values using each elements name-attribute as the array index and the element's value as the array value.
So if you had an , the entered text is stored at $_GET['foo']. If you used the post-method, the values are stored in the $_POST array.

If you want the user to stay at the same page, you can simply specify the form like this: action="?".

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you retrieve an HTML option value using PHP?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the correct HTML for making a drop-down list?

<select> <option value="Volvo">Volvo</option> <option value="Saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="Audi">Audi</option> </select>


What is difference between name and value in an HTML Form?

'Name' can be a field and 'value' can defined to the that particular field. Example: <select name="Car List"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi</option> </select>


How do you add item in listbox through the textbox?

This can be done with a little javascript. Here's an example <html> <head> <script type="text/javascript" language="javascript"> function addNewItem() { // Retrieve the elements from the document body var textbox = document.getElementById('MyTextbox'); var listbox = document.getElementById('MyListbox'); // Now we need to create a new 'option' tag to add to MyListbox var newOption = document.createElement('option'); newOption.value = textbox.value; // The value that this option will have newOption.innerHTML = textbox.value; // The displayed text inside of the <option> tags // Finally, add the new option to the listbox listbox.appendChild(newOption); } </script> </head> <body> <input id="MyTextbox" type="textbox" /> <input type="button" value="Add Item" onclick="javascript:addNewItem()" /> <br /><br /> <select id="MyListbox" size="10"> <option value="apples">Apples</option> <option value="oranges">Oranges</option> <option value="bananas">Bananas</option> </select> </body> </html>


How do you enable the select box after previous select box value selected?

The code: <html> <head> <script type="text/javascript" language="javascript"> function disableBox() { document.getElementById("select2").disabled = true; } function enableBox() { if(document.getElementById("select1").value =="USA") { document.getElementById("select2").disabled = false; } else { document.getElementById("select2").disabled = true; } } </script> </head> <body onload="disableBox()"> <form> <select name="country" id="select1" onchange="enableBox()"> <option>Default</option> <option value="USA">USA</option> </select><br /> <select name="state" id="select2"> <option value="New Jersey">New Jersey</option> <option value="Texas">Texas</option> <option value="New York">New York</option> </select> </form> </body> </html>


What is an HTML source?

HTML source simply refers to the markup language that makes up a web page. You can view the HTML source for this page by using your browser's "View Source" or "View Source Code" menu option.


How do you import Excel spreadsheet into HTML?

You do not really import an excel spreadsheet into HTML. You can SaveAs and select HTML as an option.


How to display listbox selected value in a texbox?

Here's the code: <head> <title>List Box Value in Text Box</title> <script type="text/javascript" language="javascript"> function getValue(string) { document.getElementById("text").value = string; } </script> </head> <body> <form name="form1"> <h2>Get Selected Value</h2> <select name="select" size="5" onclick="getValue(this.value)"> <option value="apple">Apple</option> <option value="tangerines">Tangerines</option> <option value="banana">Banana</option> <option value="grapes">Grapes</option> </select> <input type="text" id="text" name="text" /> </form> </body> </html>


How do you change HTML attribute using HTML dom?

You can change HTML attributes easily. Using Dom that can be done using JavaScript.


How do you disable one combobox by selecting some values in another combobox using java script?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/HTML; charset=iso-8859-1" /> <title>Untitled Document</title> </head><script type="text/javascript"> function val() { document.getElementById("fgh").disabled="true"; } </script> <body> <label> <select name="select" onchange="return val()"> <option value="hjk">jhk</option> <option value="hgfh">dfgdf</option> </select> </label> <label> <select name="select2" id="fgh"> </select> </label> </body> </HTML>


How do I put videos on my website using HTML?

If you want to put a youtube video onto your website then click on the share button. Then click on the option Embed. There will be HTML text, all you have to do is copy and paste that. :) Good luck!


Html codes for feedback form?

<!doctype html> <html> <head> <meta charset="utf-8"> <title>Feedback Form</title> </head> <body> <h1>Feedback Form</h1> <form action="mailto:your email address" method="get" enctype="text/plain"> <p> Name: <input type="text" id="name" size="30"> </p> <p> Please rate my site from 1 to 10 (1 = bad and 10 = good): <br /> <select id="rating"><br /> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> <option selected>10</option> </select> </p> <p> How would you suggest I improve it?<br /> <textarea id="improve" rows="5" cols="30"></textarea> </p> <p> <input type="submit" value="Send Feedback"> <input type="reset"> </p> </form> </body> </html>


Html pull down menu example for month day and year I would like to get an example on how to write month day and year in HTML form?

# <select name="month" id="month"> # <option value="1" <?PHP if($month==1) echo "selected";?>>January</option> # <option value="2" <?PHP if($month==2) echo "selected";?>>February</option> # <option value="3" <?PHP if($month==3) echo "selected";?>>March</option> # <option value="4" <?PHP if($month==4) echo "selected";?>>April</option> # <option value="5" <?PHP if($month==5) echo "selected";?>>May</option> # <option value="6" <?PHP if($month==6) echo "selected";?>>June</option> # <option value="7" <?PHP if($month==7) echo "selected";?>>July</option> # <option value="8" <?PHP if($month==8) echo "selected";?>>August</option> # <option value="9" <?PHP if($month==9) echo "selected";?>>September</option> # <option value="10" <?PHP if($month==10) echo "selected";?>>October</option> # <option value="11" <?PHP if($month==11) echo "selected";?>>November</option> # <option value="12" <?PHP if($month==12) echo "selected";?>>December</option> # </select> # # <select name="day" id="day"> # <option value="1" <?PHP if($day==1) echo "selected";?>>1</option> # <option value="2" <?PHP if($day==2) echo "selected";?>>2</option> # <option value="3" <?PHP if($day==3) echo "selected";?>>3</option> # <option value="4" <?PHP if($day==4) echo "selected";?>>4</option> # <option value="5" <?PHP if($day==5) echo "selected";?>>5</option> # <option value="6" <?PHP if($day==6) echo "selected";?>>6</option> # <option value="7" <?PHP if($day==7) echo "selected";?>>7</option> # <option value="8" <?PHP if($day==8) echo "selected";?>>8</option> # <option value="9" <?PHP if($day==9) echo "selected";?>>9</option> # <option value="10" <?PHP if($day==10) echo "selected";?>>10</option> # <option value="11" <?PHP if($day==11) echo "selected";?>>11</option> # <option value="12" <?PHP if($day==12) echo "selected";?>>12</option> # <option value="13" <?PHP if($day==13) echo "selected";?>>13</option> # <option value="14" <?PHP if($day==14) echo "selected";?>>14</option> # <option value="15" <?PHP if($day==15) echo "selected";?>>15</option> # <option value="16" <?PHP if($day==16) echo "selected";?>>16</option> # <option value="17" <?PHP if($day==17) echo "selected";?>>17</option> # <option value="18" <?PHP if($day==18) echo "selected";?>>18</option> # <option value="19" <?PHP if($day==19) echo "selected";?>>19</option> # <option value="20" <?PHP if($day==20) echo "selected";?>>20</option> # <option value="21" <?PHP if($day==21) echo "selected";?>>21</option> # <option value="22" <?PHP if($day==22) echo "selected";?>>22</option> # <option value="23" <?PHP if($day==23) echo "selected";?>>23</option> # <option value="24" <?PHP if($day==24) echo "selected";?>>24</option> # <option value="25" <?PHP if($day==25) echo "selected";?>>25</option> # <option value="26" <?PHP if($day==26) echo "selected";?>>26</option> # <option value="27" <?PHP if($day==27) echo "selected";?>>27</option> # <option value="28" <?PHP if($day==28) echo "selected";?>>28</option> # <option value="29" <?PHP if($day==29) echo "selected";?>>29</option> # <option value="30" <?PHP if($day==30) echo "selected";?>>30</option> # <option value="31" <?PHP if($day==31) echo "selected";?>>31</option> # </select> # # <select name="year" id="year"> # <?PHP for($i=date("Y"); $i<=date("Y")+2; $i++) # if($year == $i) # echo "<option value='$i' selected>$i</option>"; # else # echo "<option value='$i'>$i</option>"; # ?> # </select>