jcstanley Posted March 4, 2008 Share Posted March 4, 2008 Hi I am having trouble getting a jumpmenu to work within a function. The dropdown select box does display the correct names ($row_rsSpring['name']). When the 'Go' button is clicked a new window opens but displays a blank page "about:blank". It worked ok "stand alone" but not now it is in a function. <?php function spring($year, $database_psc,$psc){ mysql_select_db($database_psc, $psc); $query_rsSpring = "SELECT * FROM springresults WHERE `year` = $year ORDER BY sprresultsid ASC"; $rsSpring = mysql_query($query_rsSpring, $psc) or die(mysql_error()); $row_rsSpring = mysql_fetch_assoc($rsSpring); $totalRows_rsSpring = mysql_num_rows($rsSpring); if ($totalRows_rsSpring < '1'){ echo '<b><font face:arial;>No Results</font></b>';} else {?> <select name="jumpMenu" id="jumpMenu"> <option value="">Select Race</option> <?php do { ?> <option value="<?php echo $row_rsSpring['file']?>"><?php echo $row_rsSpring['name']?></option> <?php } while ($row_rsSpring = mysql_fetch_assoc($rsSpring)); $rows = mysql_num_rows($rsSpring); if($rows > 0) { mysql_data_seek($rsSpring, 0); $row_rsSpring = mysql_fetch_assoc($rsSpring); } ?> </select> <br /> <input type="button" name="go_button" id= "go_button" value="Go" onclick="MM_jumpMenuGo('jumpMenu','blank',0)" /> <?php mysql_free_result($rsSpring); }?> </div> </form> <?php } ?> the jumpmenu javascript function located in the head is: <script type="text/javascript"> <!-- function MM_jumpMenuGo(objId,targ,restore){ //v9.0 var selObj = null; with (document) { if (getElementById) selObj = getElementById(objId); if (selObj) window.open(selObj.options[selObj.selectedIndex].value); if (restore) selObj.selectedIndex=0; } } //--> </script> Any suggestions what could be the problem? Thanks Quote Link to comment Share on other sites More sharing options...
haku Posted March 4, 2008 Share Posted March 4, 2008 Yep. You don't have an opening form tag. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 4, 2008 Share Posted March 4, 2008 i may be wrong, but i don't think that's the problem. the window is opening, the javascript is working. the problem seems to be that the window isn't getting which file to open. is the value of $row_rsSpring['file'] correct? Quote Link to comment Share on other sites More sharing options...
jcstanley Posted March 4, 2008 Author Share Posted March 4, 2008 Well spotted haku!!! - however it still doesn't work Modified code: <?php function spring($year, $database_psc,$psc){ mysql_select_db($database_psc, $psc); $query_rsSpring = "SELECT * FROM springresults WHERE `year` = $year ORDER BY sprresultsid ASC"; $rsSpring = mysql_query($query_rsSpring, $psc) or die(mysql_error()); $row_rsSpring = mysql_fetch_assoc($rsSpring); $totalRows_rsSpring = mysql_num_rows($rsSpring); if ($totalRows_rsSpring < '1'){ echo '<b><font face:arial;>No Results</font></b>';} else {?> <form> <select name="jumpMenu" id="jumpMenu"> <option value="">Select Race</option> <?php do { ?> <option value="<?php echo $row_rsSpring['file']?>"><?php echo $row_rsSpring['name']?></option> <?php } while ($row_rsSpring = mysql_fetch_assoc($rsSpring)); $rows = mysql_num_rows($rsSpring); if($rows > 0) { mysql_data_seek($rsSpring, 0); $row_rsSpring = mysql_fetch_assoc($rsSpring); } ?> </select> <br /> <input type="button" name="go_button" id= "go_button" value="Go" onclick="MM_jumpMenuGo('jumpMenu','blank',0)" /> <?php mysql_free_result($rsSpring); }?> </div> </form> <?php } ?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 4, 2008 Share Posted March 4, 2008 is the value of $row_rsSpring['file'] correct? Quote Link to comment Share on other sites More sharing options...
jcstanley Posted March 4, 2008 Author Share Posted March 4, 2008 is the value of $row_rsSpring['file'] correct? how can i tell? Just checked the value in the database and it is correct . Quote Link to comment Share on other sites More sharing options...
haku Posted March 4, 2008 Share Posted March 4, 2008 Try changing if (selObj) window.open(selObj.options[selObj.selectedIndex].value); to if (selObj) window.open(selObj.options[selectedIndex].value); And if that doenst work, try if (selObj) window.open(selObj.options[selectedIndex].firstChild.data); Quote Link to comment Share on other sites More sharing options...
jcstanley Posted March 4, 2008 Author Share Posted March 4, 2008 Try changing if (selObj) window.open(selObj.options[selObj.selectedIndex].value); to if (selObj) window.open(selObj.options[selectedIndex].value); And if that doenst work, try if (selObj) window.open(selObj.options[selectedIndex].firstChild.data); tried both lines but gave an error: "selectedIndex' is undefined Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 4, 2008 Share Posted March 4, 2008 is the value of $row_rsSpring['file'] correct? how can i tell? Just checked the value in the database and it is correct . look at the page source. see what's in the option values. what are the values for each option? Quote Link to comment Share on other sites More sharing options...
jcstanley Posted March 4, 2008 Author Share Posted March 4, 2008 is the value of $row_rsSpring['file'] correct? how can i tell? Just checked the value in the database and it is correct . look at the page source. see what's in the option values. what are the values for each option? looked at page source and the option values are there! ??? ]<select name="jumpMenu" id="jumpMenu"> <option value="">Select ...</option> <option value="/results/2007/spring/springwed.htm">Wednesday</option> <option value="/results/2007/spring/springsunshort.htm">Sunday Short Race</option> <option value="/results/2007/spring/springsunlong.htm">Sunday Long Race</option> </select> <br /> <input type="button" name="go_button" id= "go_button" value="Go" onclick="MM_jumpMenuGo('jumpMenu','blank',0)" /> Quote Link to comment Share on other sites More sharing options...
haku Posted March 4, 2008 Share Posted March 4, 2008 Ok, then I changed something I shouldn't have. Try this: if (selObj) window.open(selObj.options[selObj.selectedIndex].firstChild.data); Do you have a link to the page? Quote Link to comment Share on other sites More sharing options...
jcstanley Posted March 4, 2008 Author Share Posted March 4, 2008 Ok, then I changed something I shouldn't have. Try this: if (selObj) window.open(selObj.options[selObj.selectedIndex].firstChild.data); Do you have a link to the page? right, we are getting somewhere: i just tried that line of code and now instead of getting 'about:blank' it tries to open the name of the first option. eg. www.xyz.com/Select%20Race Quote Link to comment Share on other sites More sharing options...
jcstanley Posted March 4, 2008 Author Share Posted March 4, 2008 Can anyone suggest another way or better way this can be done? looks like we are stumped! Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 4, 2008 Share Posted March 4, 2008 in doubt, simplify the JS. maybe try something that directly references the objects instead of trying to grab them by ID: <script type="text/javascript"> <!-- function MM_jumpMenuGo() { window.open(document.jumpForm.jumpMenu.options[document.jumpForm.jumpMenu.selectedIndex].value); } //--> </script> <form NAME='jumpForm'> ..... etc. Don't forget to give the form a name, in this case jumpForm. Quote Link to comment Share on other sites More sharing options...
haku Posted March 4, 2008 Share Posted March 4, 2008 Again, do you have a link? It would be a lot easier for me to just try it myself than to guess over the forum. Quote Link to comment Share on other sites More sharing options...
jcstanley Posted March 5, 2008 Author Share Posted March 5, 2008 in doubt, simplify the JS. maybe try something that directly references the objects instead of trying to grab them by ID: <script type="text/javascript"> <!-- function MM_jumpMenuGo() { window.open(document.jumpForm.jumpMenu.options[document.jumpForm.jumpMenu.selectedIndex].value); } //--> </script> <form NAME='jumpForm'> ..... etc. Don't forget to give the form a name, in this case jumpForm. nice idea but it gives an error: 'document.jumpForm.jumpMenu' is null or not an object. Again, do you have a link? It would be a lot easier for me to just try it myself than to guess over the forum. here is the link http://www.cashregisters-cornwall.com/jumpmenu/jumpmenu.php it opens a new window but uses the option name, not the value. Quote Link to comment Share on other sites More sharing options...
haku Posted March 5, 2008 Share Posted March 5, 2008 Here you go: function MM_jumpMenuGo(objId,targ,restore) { //v9.0 var selObj = null; if (document.getElementById) selObj = document.getElementById(objId) if (selObj) window.open(selObj.getElementsByTagName("option")[selObj.selectedIndex].value) return false; } This works. You can actually take out the 'targ' variable and the 'restore' variable, as neither of them are being used. Quote Link to comment Share on other sites More sharing options...
jcstanley Posted March 5, 2008 Author Share Posted March 5, 2008 Thank you very much haku!!!!!!! That is great - works perfectly Quote Link to comment Share on other sites More sharing options...
haku Posted March 5, 2008 Share Posted March 5, 2008 No worries. One thing though - you have the submit button set up as type="button". You should change this to type="submit", and set up the form so that it submits and works without javascript turned on, just to be safe. That is how javascript is supposed to be used. 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.