The HTML with the select value is:
<select id="value_select" onchange="get_value_js()">
<option>Value 1</option>
<option>Value 2</option
</select>
The JavaScript code:
function get_value_js() {
var the_value = document.getElementById("value_select").value;
}
I don't know how to continue the JavaScript to send the value to, for example, work.php. In work.php, I want to store the value in a PHP variable.
You can use AJAX.
function get_value_js(){
var xmlhttp;
var e = document.getElementById("value_select");
var the_value = e.options[e.selectedIndex].value;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//Do whatever with xmlhttp.responseText;
}
}
xmlhttp.open("GET","work.php?val="+the_value,true);
xmlhttp.send();
}
You can use $_GET['the_value'] to grab the value.
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