php - how to get dynamic value by ajax function call -


on web page have text area enter image description here

and suppose data in textarea when alternate value of select box( or onchange event), used ajax function

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>         <script>                                           function mycall() {                     var request = $.ajax({                         url: "ajax.php",                         type: "get",                                     datatype: "html"                     });                      request.done(function(msg) {                         $("#mybox").html(msg);                               });                      request.fail(function(jqxhr, textstatus) {                         alert( "request failed: " + textstatus );                     });                 }          </script> 

and select box code,

<select name="txtname" id="txtname" onchange="mycall()" >     <option value="0">select age:</option>     <option value="100083">100083</option>     <option value="22-26">22-26</option>     <option value="26-30">26-30</option>     <option value="30-34">30-34</option>      </select> 

actualy want fetch record on basis of select box value, function working fine static value puzzled how data data base.. , ajax page coding here..

<?php    $con=mysql_connect("localhost","root",""); if (!$con)   {   die('could not connect: ' . mysql_error());   }  mysql_select_db("hmc", $con);   $sql="select * news name = '22-26'";  $result = mysql_query($sql); ?>                          <?php   while($row=mysql_fetch_array($result)) { ?>         <tr> <td> <?php echo $row['news1'];?></h3></td>  </tr><br /><hr /><br />  <?php } ?>     </div> 

any idea appreciated...

your ajax call not proper, need pass select box value php side, this

$.ajax({                     url: "ajax.php",                     type: "get",                                 datatype: "html",                     data:"value="+$("#txtname").val();                 }); 

then use value on php side using $_get['value']


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -