Jump to content

Problem with jumpmenu in a function


jcstanley

Recommended Posts

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

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 }  ?>

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);

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

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)" />

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

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.

 

 

 

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.

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.