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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.