digitalgod Posted August 11, 2006 Share Posted August 11, 2006 hey guys,I'm trying to make 2 dynamic drop downs where the 2nd one is populated with elements from a db depending on what was selected in the 1st drop down.The first drop down is populated with an array, it contains the days of the week. So when you choose a day I want the second drop down to be populated with the names of clubs that are opened on that day.something like SELECT club FROM clubnights WHERE club = "monday"this is what I have so far (got it from nogray's post somewhere on this forum[code]<?php$query = "SELECT * FROM clubs";$result = mysql_query ($query);while ($row = mysql_fetch_array($result)) { $query1 = "SELECT * FROM clubnights WHERE club = '".$row['name']."'"; $result1 = mysql_query ($query1); if ($row['name'] !='') { $sub_arrays .= "subs[".$row['name']."] = new Array("; while ($row1 = mysql_fetch_array($result1)) { $sub_arrays .= "\"".$row1['club']."\","; } $sub_arrays = trim($sub_arrays, ",") .");\n"; }}list($y,$m,$d) = explode("-",date("Y-m-d"));$days = array();for ($i=0;$i<=6;$i++) { array_push($days,date("l", mktime(0,0,0,$m,$d+$i,$y)));}?><script language="javascript">var subs = new Array();<?= $sub_arrays ?>function fill_subs(val){ if (val != ""){ var sub_sel = document.getElementById('club'); sub_sel.innerHTML=""; opt = document.createElement("OPTION"); opt.value = ""; opt.innerHTML = "Select"; sub_sel.appendChild(opt); for(i=0; i<subs[val].length; i++){ opt = document.createElement("OPTION"); opt.value = subs[val][i]; opt.innerHTML = subs[val][i]; sub_sel.appendChild(opt); } }}</script>//......<form name="list" method="post" action="index.php?a=list"> <input type="hidden" name="process_a" value="yes"/> <? echo '<select name="night" onChange="fill_subs(this.value);"><option value="">Select one</option>'; for($i=0;$i<count($days);$i++) { echo '<option value='.strtolower($days[$i]).'>'.$days[$i].'</option>'; } echo "</select>"; echo '<select id="club" name="club"><option value="">Select one</option>'; echo "</select>"; ?> </form>[/code]it keeps telling me that I have an error on line 200 which is the onChange event : <select name="night" onChange="fill_subs(this.value);">any ideas what I'm doing wrong? Quote Link to comment Share on other sites More sharing options...
may Posted August 19, 2006 Share Posted August 19, 2006 Hello!I guess u need to get rid of the semi colon after the functions name.Try this:<select name="night" onChange="fill_subs(this.value)"> Quote Link to comment Share on other sites More sharing options...
448191 Posted August 20, 2006 Share Posted August 20, 2006 Javascript ususally doesn't care if you include the semicolumn or not. The problem is probably with your use of shorthand opening tags ("[color=red][b]<?[/b][/color]"). The php within that block probably isn't parsed, as php doesn't accept it by default. Use "[b][color=red]<?php[/color][/b]" instead. Quote Link to comment Share on other sites More sharing options...
pixy Posted August 22, 2006 Share Posted August 22, 2006 Whoa, I was just needing something like this too! :) Quote Link to comment Share on other sites More sharing options...
ExosSho Posted September 8, 2006 Share Posted September 8, 2006 i dont know if u solved the problem, but maybe the mysql part isnt right,i think it should be while($row = mysql_fetch_assoc($result))insted of mysql_fetch_array.but maybe im wrong Quote Link to comment 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.