Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-21-2011, 09:34 AM   PM User | #1
tayys
New to the CF scene

 
Join Date: Oct 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
tayys is an unknown quantity at this point
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..
tayys is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:34 AM.


Advertisement
Log in to turn off these ads.