abhi123 abhi123 - 4 months ago 7
Javascript Question

I want to pass two variables in ajax code and then return one values from ajax to form

This is HTML Code:-


<input type="hidden" value="country" name="county">
<select onchange="showSoft(this.value)" name="Property_Type">
<option value="" selected="selected">Property Type </option>
<option value="industrial" id="softin">Workshop/Industrial </option>
<option value="industrial" id="softin">Workshop/Industrial </option>
</select>
<select>
<option selected>Size</option>
<option value="100" id="softsq1">100sq ft ()</option>
<option value="200" id="soft2">200sq ft </option>
<option value="300" id="soft1">300sq ft </option>
</select>


When any one select any property type from first select to another then this call to an ajax function which is this


<script>
function showSoft(str) {
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("softsq1").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "softsq.php?q="+str, true);
xhttp.send();
}
</script>


In this code ajax code i pass a value from frist select which is Property Type after that when i select that option then it upadte data but i want to pass two variables to this code i know first is
Country which is hidden
and another is
Property_Type
but i dont know how to transfer two variables in this code and after this i want to pass both variables in softsq.php file
Property_Type
variable passing fine but i want to pass both please any one can help me ?

Answer

No you not pass value by hidden but if you want to pass value by php variable so thats possible see example below:-

<?php $ab='country'; ?>  <!--/* here that hidden value */-->
<select onchange="showSoft(this.value)" name="Property_Type">
<option value="" selected="selected">Property Type </option>
<option value="industrial" id="softin">Workshop/Industrial </option> 
<option value="industrial" id="softin">Workshop/Industrial </option>
</select>
<select>
<option selected>Size</option>
<option value="100" id="softsq1">100sq ft ()</option>
<option value="200" id="soft2">200sq ft </option>
<option value="300" id="soft1">300sq ft </option>
</select>
<script>
function showSoft(str) {
  var xhttp;
  xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      document.getElementById("softsq1").innerHTML = xhttp.responseText;
      }
  };
  xhttp.open('GET', 'two.php?q='+str+'&w=<?php echo $ab; ?>', true);
  xhttp.send();
}
</script>

I wish it gonna helpfull for uh