Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    chained combo boxes problem

    Hi there,

    I failed to create the options for the second combo box depend on the selection of the first combo box.

    Is there any problem with my jquery there?
    $("#cboMain").change(function() {
    $("#cboSub").load("getter.php?choice=" + $("#cboMain").val());
    });

    Any helps are very much appreciate.

    codes for index.php:
    Code:
    <?php
    require_once 'connectDB.php';
    
    $id=$_GET['sub_id'];
    
    $sql="SELECT * FROM tb_process";
    $result=mysql_query($sql);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script language="JavaScript">
    $("#cboMain").change(function() {
    	$("#cboSub").load("getter.php?choice=" + $("#cboMain").val());
    });
    
    </script>
    
    </head>
    <body>
    <form id="form1" name="form1" method="post">
    	<select name="cboMain" id="cboMain" class="cboMain">
       		<option value="0" selected="selected">----Select Main Process----</option> 
    		<?php 
    		while ($row = mysql_fetch_array($result)) 
    		{
    			$pro_id = $row['pro_id'];
    			$pro_name = $row['pro_name'];	
    			echo "<option value='$pro_id'>$pro_name</option>";
    		}
    		?>
    	</select>
    	<select name="cboSub" id="cboSub" class="cboSub">
       		<option value="0" selected="selected">----Select Sub Process----</option> 
    	</select>
    </form>
    
    </body>
    </html>
    codes for getter.php:
    Code:
    <?php
    require_once 'connectDB.php';
    
    $choice = mysql_real_escape_string($_GET['choice']);
    
    $query = "SELECT * FROM tb_sub_process WHERE pro_id='$choice'";
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result)) 
    {
    	$sub_id = $row['sub_id'];
    	$sub_name = $row['sub_name'];	
    	$select = ($id == $sub_id) ? 'selected="selected"' : NULL;
    	echo "<option value='$sub_id' $select>$sub_name</option>";
    }
    ?>
    Last edited by tayys; 10-21-2011 at 09:37 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •