How to write php code in javascript tag -
How to write php code in javascript tag -
i have code
<select onchange="getval(this);"> <option value="">select</option> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
and script
function getval(sel){ //alert(sel.value); <?php $sql = "select * tbl_table id="?>+(sel.value) }
i want select info table id values javascript don't know how write php in javascript tag , how add together javascript's variable (sel.value)
after php
how can right syntax?
may help you. can utilize ajax...
mainfile.php
<script src="//code.jquery.com/jquery-1.10.2.js"></script> <script> function getval(x){ var data_arr="id="+x; $.ajax({ type:"post", url:"anotherfile.php", data:data_arr, success: function(response){ // here response come have deside how maintain response... } }); } </script> <select onchange="getval(this.value);"> <option value="">select</option> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
and file contain ajax code here...
anotherfile.php
<?php mysql_connect("hostname","username","password"); mysql_select_db("database_name"); $sql = "select * tbl_table id=".$_request['id']; while($row = mysql_fetch_array($sql)){ // here out set info code... } // , write info in echo statement homecoming response
hope got it...
javascript php jquery html
Comments
Post a Comment