digitalgod Posted August 9, 2006 Share Posted August 9, 2006 hey guys,I have 2 drop downs, my first one is being populated by an array but I'd like to have my 2nd one populated from a db depending on the value of the first drop down.I already know how to do it but my way requires the form to be refreshed... would there be a simple way to do is without having to reload the page? Link to comment https://forums.phpfreaks.com/topic/17065-dynamic-drop-down/ Share on other sites More sharing options...
digitalgod Posted August 9, 2006 Author Share Posted August 9, 2006 anyone??? been trying to do this for a while without any success.... Link to comment https://forums.phpfreaks.com/topic/17065-dynamic-drop-down/#findComment-72098 Share on other sites More sharing options...
kalivos Posted August 9, 2006 Share Posted August 9, 2006 Without a page refresh, you need javascript. Link to comment https://forums.phpfreaks.com/topic/17065-dynamic-drop-down/#findComment-72102 Share on other sites More sharing options...
digitalgod Posted August 9, 2006 Author Share Posted August 9, 2006 I know and I tried different solutions but without any success....here's what I have so far[code=php:0]echo '<SCRIPT language=JavaScript type=text/javascript> ';echo 'var store = new Array();';for ($i=0; $i<$numRows; $i++){ //for each item $js_array = ""; $sql = 'SELECT * FROM clubnights'; $result = mysql_query($sql) or die (mysql_errno().": select ".mysql_error()."<BR>" . $sql); while ($row = mysql_fetch_array($result)) { $js_array .= "'" . $row['club'] . "','" . $row['club'] . "',"; } $js_array = rtrim( $js_array , ","); // trim final comma echo 'store['.$i.'] = new Array('; // start javascript array echo $js_array . "); ";} // end for echo '</SCRIPT>';[/code][code]<SCRIPT language=JavaScript type=text/javascript><!-- Begin/* Execute init() function */window.onload = initialize;function initialize () { if (self.init) self.init();}function init(){ optionTest = true; lgth = document.forms[0].night.options.length - 1; document.forms[0].night.options[lgth] = null; if (document.forms[0].night.options[lgth]) optionTest = false; if (optionTest) self.populate();}function populate(){ if (!optionTest) return; var box = document.forms[0].club; var number = box.options[box.selectedIndex].value; if (!number) return; var list = store[number]; var box2 = document.forms[0].night; box2.options.length = 0; for(i=0;i<list.length;i+=2) { box2.options[i/2] = new Option(list[i],list[i+1]); }[/code]where "night" is m first drop down and "club" is my second.night is populated by an array and I want "club" to be populated depending on what night is chosenmy table clubnights looks like thisid | night | club |.....1 | Friday | Aria |2 | Thursday | Circus |..... etc so a night can have several clubsI'm really lost Link to comment https://forums.phpfreaks.com/topic/17065-dynamic-drop-down/#findComment-72107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.