-1

I have a code, where when i select a value through Drop-down, the name I am selecting should pass through a PHP variable $ch so a second drop-down which runs a mysql query.

Here is my code for first dropdown:

<select name="cha_name" id="cha_name" onChange="fillcha(this.value);">
        <option value="0">--SELECT--</option>
        <?php
            $res = mysqli_query($con, "select customer_code, customer from master_customer where is_cha = 1 order by customer") or die(mysqli_error($con));
            while($row = mysqli_fetch_array($res)){
                echo "<option value=\"".$row[1]."$$".$row[0]."\" ".(($row[1]==$wo_order[1])?"selected='selected'":"").">".$row[1]."</option>";
            }
        ?>

      </select>

When i select this, the value should be capture in a PHP variable $ch without reloading the page show the PHP variable can be used further in a mysql query. Kindly help as I am still in learning phase for JQuery and Ajax.

the mysql query is as follows:

SELECT container_no FROM  `cex_work_order_det` WHERE `cha_name`='$cha'
Amlan
  • 129
  • 1
  • 2
  • 14

1 Answers1

1

for that you have to use jquery and ajax jquery code

 <script>
  $("document").ready(function()
  {
  $("select[name='cha_name']").change(function() // function sorting Domain according to server name 
   {
      var customer_code=$("select[name='cha_name']").val();
         $.get('ajax_actions.php?act=your-act-name&customer_code='+customer_code,function(data)
        {
            alert(data);
        });
   });
   });
 </script>  

ajax_actions.php

<?php
 error_reporting(0);
 foreach ($_GET as $name => $value) { $$name = $value; }
 foreach ($_POST as $name => $value) { $$name = $value; }

// warning Dont chnage anything  in This ajax action file 
// -------------------------------------------------------------------------------
if($act=="your-act-name")  // do your actions

{ 
  // fire here your query  and echo you result here
}  
Sarjerao Ghadage
  • 1,420
  • 16
  • 31