Passing JavaScript variable to PHP on dropdown change -


i trying change text in div depending on value change on dropdown box. dropdown box values populated mysql using php. loading dropdown box on page load.

<script>  $(document).ready(function() { $('#products').change(function(){  var idval=$('#products').val(); $.ajax         (   {                 type: "post",                 url: "my.php",                 data: {winner_id:idval},                  success: function(response)                 { alert("the winner passed!")},             }         );   <?php  require_once 'config.php';   $iid=$_get['winner_id']; $sql="select * products prod_id = ".$iid; $result = mysql_query($sql); $row = mysql_fetch_array($result);  $prodcredit="credit :".$row["prod_price"]; $time="estmated time  :".$row["prod_time"];   ?>  $('#esdtime').text(' <?php echo $prodcredit ?> ' ); $('#credit').text(' <?php echo $time ?> ' );     });    });  </script> 

i not getting results.

let me know how can assign javascript value idval php variable $iid value.

//you want php script in separate file call have php file return array or json object. have callback success function append new options html select. following ruffexample  <script>    $(document).ready(function() {   $('#products').change(function(){   var idval=$('#products').val(); $.ajax     (   {             type: "post",             url: "my.php",             data: {winner_id:idval},              success: function(response){               (var = 0; < response.length; i++) {                   $("#idofyourselect").append("<option val='" +response[i]+"'>" + response[i] + "</option>");               }             },         }     );  </script> 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -