Jump to content

Connected DropDown List


Vinodpv

Recommended Posts

Connected DropDown List working in Local host not in online-- Please help me any one

 

      <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
      <script type="text/javascript" src="js/jquery-ui-1.8.17.custom.min.js"></script>

  <script type="text/javascript">
           $(document).ready(function(){          
               $('.userAddress').change(function(){
                     var company=$('.userAddress').val();
                     $.ajax({
                        type:"post",
                        url:"branch.php",
                        data:"company="+company,
                        success:function(data){
                              $("#branch").html(data);
                        }
                     });
               });

</script>

 

              <?php  $queryComp = mysql_query("SELECT comp_name FROM company");
              
              ?>
               <tr>
                <td width="125">Company</td>
                <td width="10">:</td>
            <td><select name="company" id="company" style="background:#DFDFFF" class="validate[required] userAddress">
              <option>-select your company-</option>
            <?php
            include "db_conexn.php";
            $result=mysql_query("SELECT comp_name from company order by comp_name");
            while($company=mysql_fetch_array($result)){
             
            echo "<option value=$company[comp_name]>$company[comp_name]</option>";
     
            } ?>
            </select>
             </td></tr>
     <tr><td>Branch </td><td>:</td>
           <td> <select name="branch" id="branch" style="background:#DFDFFF">
                <option>-select your branch-</option>
            </select>
                    </td>
              </tr>
branch.php

<?php
  include "db_conexn.php";
 $company=$_POST["company"];
  $result=mysql_query("select branch,comp_name FROM branch where comp_name='$company' ");
  while($branch=mysql_fetch_array($result)){
    echo"<option value=$branch[branch]>$branch[branch]</option>";
  }
?>

Link to comment
https://forums.phpfreaks.com/topic/287944-connected-dropdown-list/
Share on other sites

Do you get any messages? Is the javascript actually working? Try putting an alert or two in the javascript to see where it fails:

  <script type="text/javascript">
           $(document).ready(function(){          
               $('.userAddress').change(function(){
                     var company=$('.userAddress').val();
alert (company);
                     $.ajax({
                        type:"post",
                        url:"branch.php",
                        data:"company="+company,
                        success:function(data){
alert (data);
                              $("#branch").html(data);
                        }
                     });
               });
</script>

Hi Friends,

 

Here the problem getting like,

 

if I have more than one elements in branch its working. (Display Branches while selecting Company)

 

but if only one branch its coming blank in branch list

 

Please help....I take ......lot of time ... cant find where is the mistake

If you put an alert in the javascript as suggested do you get a window that shows the option code? If not, try accessing branch.php directly and see what you get. Also, please sanitize your input with mysql_real_escape_ string and consider mysqli instead of mysql.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.