Shair Shair - 1 year ago 106
Ajax Question

How to pass value to the second page using Javascript AJAX

I have an html select on my page

$query = mysql_query("select * from results");
echo "<select id='date' onchange='showdata()' class='form-control'>";
while ($arr = mysql_fetch_array($query)) {
echo "<option value=".$arr['month'].">".$arr['month']." / ".$arr['year']. "</option>" ;
echo "</select>";

the options are coming from database. After this I have ajax script


function showdata() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
};"GET", "result.php", true);


I want it to send the selected value in the html select to the page result.php

Answer Source

another way of doing the same thing using jquery ajax ...

<select id="item" onchange="send_item(this.value)">
 <?php $someVariable = $_GET["someVariable"];
       $query = mysql_query("select * from results");
       echo "";
     while ($arr = mysql_fetch_array($query)) {?>
<option value="<?php echo your value?>"><?php echo your value?></option>
   <?php }?>

  function send_item(str){
        url: '',
        type: "post",
        data: {
        success: function(data) {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download