HomerTheDragoon Posted August 17, 2007 Share Posted August 17, 2007 Alright, basically I have this drop down box called optone. And when u change the selection of it, it runs a function(which changes other things on the site). The form is for and online gaming league, and they are selecting their matches. It works great when i only have one entry in the database.(one match) However when i add a second match to their database it doesn't run the update on select. So the function doesn't run. Heres the code <select name="optone" size="1" onchange="setOptions(document.myform.optone.options[document.myform.optone.selectedIndex].value);"> <option value=" " selected="selected">Select a match please</option> <?$count=0; $q = mysql_query("SELECT * FROM league_matches WHERE clan1='$clan' or clan2='$clan' ORDER BY weeknum ASC"); while($row = mysql_fetch_array($q)) { echo '<option value="'.$row['matchid'].'">Week '.$row['weeknum'].': '.$row['clan1'].' vs '.$row['clan2'].'</option>'; }?> </select> If someone could help me i would greatly apreciate it. Im sure its somthing minor im doing. Quote Link to comment Share on other sites More sharing options...
php_tom Posted August 18, 2007 Share Posted August 18, 2007 I just tested the HTML since I don't have access to your database. This code seems to work perfectly: <form name='myform'> <select name="optone" size="1" onchange="alert(document.myform.optone.options[document.myform.optone.selectedIndex].value);"> <option value=" " selected="selected">Select a match please</option> <option value="1">Week 1: joe vs steve</option> <option value="2">Week 2: joe vs max</option> <option value="3">Week 2: mark vs animal</option> </select> </form> Try replacing the 'alert()' with the function you're trying to call, and put your PHP while loop back in, then try it and if it still doesn't work I'm guessing your database query is wrong. Hope that helps. Quote Link to comment Share on other sites More sharing options...
HomerTheDragoon Posted August 18, 2007 Author Share Posted August 18, 2007 yah, it works fine when u hardcode the choices. However, when i do the query, it only works for 1. The choices show, but they dont trigger the function. So thats really weird. Quote Link to comment Share on other sites More sharing options...
HomerTheDragoon Posted August 18, 2007 Author Share Posted August 18, 2007 Sorry for the double post, I fixed it, It happened to be in the function. This is what it was: <?$q = mysql_query("SELECT * FROM league_matches WHERE clan1='$clan' or clan2='$clan' ORDER BY weeknum ASC"); while($row = mysql_fetch_array($q)) {$q2 = mysql_query("SELECT * FROM league_maps WHERE week='".$row['weeknum']."'"); $row2 = mysql_fetch_array($q2); ?> if (chosen == "<?echo $row['matchid'];?>") { <?for($aa=1;$aa<6;$aa++)echo 'map'.$aa.'.src="images/maps/'.$row2['map'.$aa].'";';?> <?for($a=1;$a<7;$a++) { echo " selbox".$a.".options[selbox".$a.".options.length] = new Option('".$picked_player[$a][$row['weeknum']]."','".$picked_player[$a][$row['weeknum']]."'); selbox".$a.".options[selbox".$a.".options.length] = new Option('----------------','".$picked_player[$a][$row['weeknum']]."');"; for($i=0;$i<$max;$i++) {echo " selbox".$a.".options[selbox".$a.".options.length] = new Option('".$bnet[$i]."','".$bnet[$i]."');"; } } } ?>} And this is what it is now. <?$q = mysql_query("SELECT * FROM league_matches WHERE clan1='$clan' or clan2='$clan' ORDER BY weeknum ASC"); while($row = mysql_fetch_array($q)) {$q2 = mysql_query("SELECT * FROM league_maps WHERE week='".$row['weeknum']."'"); $row2 = mysql_fetch_array($q2); ?> if (chosen == "<?echo $row['matchid'];?>") { <?for($aa=1;$aa<6;$aa++)echo 'map'.$aa.'.src="images/maps/'.$row2['map'.$aa].'";';?> <?for($a=1;$a<7;$a++) { echo " selbox".$a.".options[selbox".$a.".options.length] = new Option('".$picked_player[$a][$row['weeknum']]."','".$picked_player[$a][$row['weeknum']]."'); selbox".$a.".options[selbox".$a.".options.length] = new Option('----------------','".$picked_player[$a][$row['weeknum']]."');"; for($i=0;$i<$max;$i++) {echo " selbox".$a.".options[selbox".$a.".options.length] = new Option('".$bnet[$i]."','".$bnet[$i]."');"; } }?> [b]}<? }?>[/b] I closed the javascript if statement inside the php brackets so it thought i was closing the while loop instead 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.