javascript - fetch data and show it in textbox with ajax -
as can see current code doesnt work , need guys...i want filter in search(textbox) , show data filtered in there corresponding textboxes...can make code work?? i've been looking in google hours same idea of program works cant find me please.
example expected output:
html code:
<form method="post"> search batchcode: <input type="text" id="query" /><br /> <table> <tr> <td> id: <br /> <input id="result" type="text" name="id1" /> <br /> <input id="result" type="text" name="id2" /> <br /> </td> <td> name: <br /> <input id="result" type="text" name="name1" /> <br /> <input id="result" type="text" name="name2" /> <br /> </td> <td> score 1: <br /> <input id="result" type="text" name="opta1" /> <br /> <input id="result" type="text" name="opta2" /> <br /> </td> <td> score 2: <br /> <input id="result" type="text" name="optb1" /> <br /> <input id="result" type="text" name="optb2" /> <br /> </td> <td> other qualification: <br /> <input id="result" type="text" name="other_qual1" /> <br /> <input id="result" type="text" name="other_qual2" /> <br /> </td> <td> interview: <br /> <input id="result" type="text" name="interview1" /> <br /> <input id="result" type="text" name="interview2" /> <br /> </td> <td> total: <br /> <input id="result" type="text" name="total1" /> <br /> <input id="result" type="text" name="total2" /> <br /> </td> </tr> </table> </form>
script function:
<script type="text/javascript"> $(document).ready(function(){ $('input[name^=search]').click(function(e){ e.preventdefault(); $.ajax({ url:"search.php", type:"post", data : { term : $('#query').val() }, datatype:json, success : function(result) { alert(result); } }); }) }); </script>
search.php page:
<?php $q = $_get['term']; mysql_connect("localhost","root",""); mysql_select_db("test"); $query = mysql_query("select * score batchcode '$q%'"); $data = array(); while($row = mysql_fetch_array($query)){ $data[]=array('value'=>$row['batchcode']); $id[] = $row['id']; $name[] = $row['name']; $score1[] = $row['score1']; $score2[] = $row['score2']; $other_qual[] = $row['other_qual']; $interview[] = $row['interview']; $total[] = $row['total']; } echo json_encode($data); ?>
there isn't "search" button click handler. try add button after search input, this:
search batchcode: <input type="text" id="query" /><br /> <input type="button" id="search" value="search"/>
Comments
Post a Comment