Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP + AJAX code - Display data on selecting a value from a list
    text
    copied!<p>I'm trying to display data from database(MySQL) based on the option fields selected. I have two fields as shown below :</p> <p><strong>Select a Health Block : .......(list) <br/> Select the year : .......(list)</strong></p> <p>When I select health block and year, data from database should be displayed on the same page itself. I've tried the following code. Actually the code works if I've only one option ('year') to be selected. What I need is to pass both the values (Health block and Year) to the page (getblock2.php) where I've written the code to retrieve data from database. Can anybody please help me to figure out where the problem is?</p> <h2>Mainpage</h2> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; var str11; var str22; function showB(str2) { str22=str2; } function showBlock2(str) { showB(); str11=str; if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getblock2.php?q="+str11+"&amp;h="+str22,true); xmlhttp.send(); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; Select a Health block &lt;select name="h" onChange="showB(this.value)"&gt; &lt;option value="1"&gt;H1&lt;/option&gt; &lt;option value="2"&gt;H2&lt;/option&gt; &lt;/select&gt; &lt;br/&gt; Select a year &lt;select name="yr" onChange="showBlock2(this.value)"&gt; &lt;option&gt;2012&lt;/option&gt; &lt;option&gt;2013&lt;/option&gt; &lt;/select&gt; &lt;div id="txtHint" style="width:570px; height:auto" &gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <h2>getblock2.php</h2> <pre><code>&lt;?php include("connect.php"); $q=$_GET["q"]; $h=$_GET['h']; $q="select Total_Cases from epidemics where Year1=$q and Hid=$h"; $r=mysql_query($q); $i=0; while($row=mysql_fetch_row($r)) { $i++; echo $i." ".$row[0]."&lt;br/&gt;"; } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload