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 Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/ 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. Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-482794 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? Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-482800 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 } ?> Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-482802 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? Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-482808 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 . Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-482815 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); Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-482816 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 Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-482824 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? Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-482827 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)" /> Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-482837 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? Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-482841 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 Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-482847 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! Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-482866 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. Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-482998 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. Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-483005 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. Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-483701 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. Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-483760 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 Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-483763 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. Link to comment https://forums.phpfreaks.com/topic/94263-problem-with-jumpmenu-in-a-function/#findComment-483766 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.