Sending a value from an HTML select to PHP with JavaScript

The HTML with the select value is: Value 1 Value 2 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.……………………

via HTML Language Development » Search Results » ajax:

Sending a value from an HTML select to PHP with JavaScript

The HTML with the select value is:

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

You could either send it as an AJAX call if you want to stay on the same page or perform a redirect and pass the value as query string parameter:
window.location.href = ‘/work.php?value=’ + encodeURIComponent(the_value);
……………………………………….

You need to enclose the

Please note that i’ve added value attributes to the