nasirmughal Posted June 4, 2008 Share Posted June 4, 2008 Dear All I m working on a PHP form that basic work is to get the details and save it in the Database of Mysql. In this form i have two multi selection Drop Down lists that are interconnected with each other using Ajax Function means when i click one record from 1st Dropdownlist it will show me all records related to this 1st dropdowlist selected record (Parent-child relationship). But here I m using a simple Ajax function that didn't fresh the page. I have problem that If i select Multiple records from the first Dropdownlist then it will not show all of related records to the 2nd Dropdownlist. So please Help me to get these all records by selecting multiple selection from Dropdownlist1. I have already done this thing using Simple javascript function but using Ajax i m confused how to get 1st Dropdownlist array value in Javascript and pass it to next page that shows ajax dropdownlist. My whole code of two different files is as below: ****************** Main File Having 1st Dropdownlist *************** <?php require('opendb.php'); require('cp/includes/global_functions.php'); ?> <html> <head> <title>Untitled Document</title> <SCRIPT type=text/javascript> function sbAjaxLib1() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { //document.myForm.time.value=xmlHttp.responseText; //var strMods = xmlHttp.responseText; var strMods = xmlHttp.responseText document.getElementById('div_modselect').innerHTML= strMods; //alert(document.getElementById('div_modselect').innerHTML); } } var sb_mkId = document.getElementById('csi_cat_id[]').value; xmlHttp.open("GET","getcsi1.php?<?=$qstr?>&csi_cat_id=" + sb_mkId ,true); xmlHttp.send(null); } function show_info(URL) { document.f1.action = URL; document.f1.submit(); } </SCRIPT> </head> <body> <form name="f1" method="get" > <td><span class="link_readmore_black"> Select CSI Category : <span class="txt_orange_11"> *</span> <br /> <? $yes1 = "yes"; $sql = "Select * from tbl_csi_cat where csi_cat_status = '".$yes1."' order by csi_cat_name ASC"; $result = mysql_query($sql) or die (mysql_error()); $num_rows = mysql_num_rows($result); ?> <select size="5" name="csi_cat_id[]" id="csi_cat_id[]" class="width_320" style="width:250px;" multiple="multiple" onchange="javascript:sbAjaxLib1();"> <option value="" selected="selected">-- Select CSI Type --</option> <? while($catalog=mysql_fetch_array($result)) { ?> <option value="<?=$catalog["csi_cat_id"];?>"> <? echo $catalog["csi_cat_code"];?> - <? echo $catalog["csi_cat_name"];?> </option> <? } ?> </select> </span></td> </tr> <tr> <td valign="top"> <div id="div_modselect"> </div> </td> </form> </body> </html> ********************** For Ajax 2nd Dropdownlist the Below file (That file only show 2nd dropdownlist on 1st Page as an Ajax) <?php require('opendb.php'); $csi_cat_id = $_REQUEST["csi_cat_id"]; for($i = 0; $i < sizeof($csi_cat_id); $i++) { $csid .= str_replace("%5B%5D","",$csi_cat_id[$i])."," ; $cslen = strrev(strlen($csid))-1; $csid_1 = substr($csid,0,$cslen); } //echo $csid_1; //exit; $sinfo2 = "<select name='csi_id[]' id='csi_id[]' class='width_320' style='width:250px;' multiple='multiple' size='5'>"; $yes1 = "yes"; $sql = "Select * from tbl_csi where csi_status = '".$yes1."' and csi_cat_id IN (". $csid_1 .")"; //echo $sql; // exit; $result = mysql_query($sql) or die (mysql_error()); $num_rows = mysql_num_rows($result); $sinfo2 .= "<option value='0'>-- Select CSI --</option>"; while ($catainfo=mysql_fetch_array($result)) { $sinfo2.= "<Option value=".$catainfo["csi_id"].">".$catainfo["csi_name"]."</Option>"; } $sinfo2.= "</select>"; echo ($sinfo2); ?> Link to comment https://forums.phpfreaks.com/topic/108662-getting-php-multiple-select-box-array-in-javascript/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.