Forum Moderators: open

Message Too Old, No Replies

Javascript Jump Menus

Works on one page but not others...WHY?

         

evmedia

10:21 pm on Feb 25, 2007 (gmt 0)

10+ Year Member



I have a website that needs a jump menu on 6 different pages so that users can easily go back and forth between the pages. I added the jump menu to the first page and it works properly, I then added the exact same code to the other pages and they do not seem to work when i change the selection...anything I need to change between pages? Form name?...i am not sure...thanks.

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>

<form name="form1">
<select name="menu1" onChange="MM_jumpMenu('window.open()',this,0)">
<option selected>Select Day</option>
<option value="http://www.example.com/monday.html">Monday</option>
<option value="http://www.example.com/tuesday.html">Tuesday</option>
<option value="http://www.example.com/wednesday.html">Wednesday</option>
<option value="http://www.example.com/thursday.html">Thursday</option>
<option value="http://www.example.com/friday.html">Friday</option>
<option value="http://www.example.com/saturday.html">Saturday</option>
</select>
</form>

[edited by: encyclo at 12:59 pm (utc) on Feb. 27, 2007]
[edit reason] examplified, see TOS [webmasterworld.com] [/edit]

vincevincevince

1:32 pm on Feb 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There should be nothing to change. My best guess is you have some other javascript on the other page which is broken and causing all javascript not to work.

Try using firefox and typing javascript: in the URL bar. Use the jump menu and you should see some errors appearing. Let us know the error which happens when the jump menu is used.

rocknbil

7:53 pm on Feb 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should also be able to hunt down script errors in FireFox under Tools-> Javascript Console.

Are you sure it's actually NOT working?

<select name="menu1" onChange="MM_jumpMenu('window.open()',this,0)">

If you execute a window.open without setting a unique id on the window, every call to this function will cause the new content to open in the same window. So when you go to the "other" pages after opening the first one, be sure to re-check this newly opened window, it may be working but doensn't appear to be because no new window is popping up.

I would advise against using a pop-up window for this very reason, but more importantly it's extremely annoying. Use pop up windows only if there is absolutely, positively, irrevokably no other way. They may seem cool "because you can" but they are not all that cool.

If you must use a new window, do it this way:

<select name="menu1" onChange="down_with_dreamweaver_MM(this)">


<script type="text/javascript">
function down_with_dreamweaver_MM(obj) {
// Define the parameters of your window.
// Never, ever ever make it unsizable,
// and you should always include scrollbars
var params = 'width=400,height=500,resizable,scrollbars';
// Set a unique id using time and date
var day = new Date();
var id = day.getTime();
// 'obj' is the select list object.
// Assuming you have a URL for the obj. value.
var ind = obj.selectedIndex;
var url = obj[ind].value;
var win = open(url,id,params);
}
</script>

Untested but pretty academic, that should work.