tayys Posted October 21, 2011 Share Posted October 21, 2011 hi, I try to create 2 combo box where the second one will depends on the selection of the first one. But it failed to pass the value to cboSub upon the onchange="load();" of cboMain. Anyway I can fix it? Thanks in advance. Here's code for index.php: <?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" /> <title>OSSP-E-Store</title> <script language="JavaScript"> function load() { $("#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" onchange="load();"> <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" onchange=""> <option value="0" selected="selected">----Select Sub Process----</option> </select> </form> </body> </html> Here's code for getter.php: <?php require_once 'connectDB.php'; $choice = mysql_real_escape_string($_GET['choice']); echo $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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/249507-helps-on-chained-comboboxes/ Share on other sites More sharing options...
tayys Posted October 21, 2011 Author Share Posted October 21, 2011 I'm not sure if I'm on the right track or not. Any advice would be appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/249507-helps-on-chained-comboboxes/#findComment-1281028 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.