Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Jump Menu headache

How to add/pass variables to same page

1:34 pm on Jan 31, 2008 (gmt 0)

Preferred Member

10+ Year Member

joined:Mar 1, 2003
votes: 4

Hi there,

If anyone could shed light on this, I'd appreciate it (I've been tasked with finishing an old abandoned website whose original coder has long departed for more lucrative gigs)

I have a jump menu on a page that is dynamically created. Underneath that menu is some product details (price, weight etc) that relate to whatever item has been selected in the drop down. If the user clicks another item, an 'onchange' event reloads the page with the new details. My problem is, I think, that I don't know how to reference the detail area with the Javascript function. What I have at the mo' is this:

function MM_jumpMenu(selObj,restore) {
if (restore) selObj.selectedIndex=0;

and the form and text area is:

<form name="form2" method="post" action="page.php">
<SELECT NAME="bob" onChange="MM_jumpMenu(this,1)">

<OPTION VALUE="page.php?var1=1&var2=1" SELECTED>Item 1</OPTION>

<OPTION VALUE="page.php?var1=1&var2=2" SELECTED>Item 2</OPTION>



<TD><?php echo ...price...?></TD>
<TD><?php echo ...price...?></TD>

'var2' is the new variable added to the URL when it refreshes. At the moment nothing happens so if this makes sense to anyone, I'd appreciate your feedback.

5:03 pm on Jan 31, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
votes: 0

Gads I hate Macromedia Javascript. :-) I'm not sure what you mean by "nothing happens," because it seems to be jumping fine here. Perhaps elaborate on what should happen and what is not. If it's not reconstructing the info area, it's something in your PHP?

In the meantime: you have SELECTED on all items. This causes the last item in your list to be selected.

Selected should be only set for the single selected item in the list, and then only if it's not the first item.

Second, it's a good idea to have the first item a blank.

Last, the eval function is for evaluating math, not text - it works fine, and is often (ab)used to evaluate strings, it's just not what it's for.

A revised 'script:

<script type="text/javascript">
function jump (selObj) {
var sel = selObj.options[selObj.selectedIndex].value;
if (sel!= '') { window.location = sel; }
return false;

<form name="form2" method="post" action="page.php">
<select name="bob" onChange="jump(this)">
<option value="">Select</option>
<option value="page.php?var1=1&var2=1">Item 1</option>
<option value="page.php?var1=1&var2=2" >Item 2</option>
7:58 am on Feb 1, 2008 (gmt 0)

Preferred Member

10+ Year Member

joined:Mar 1, 2003
votes: 4

rocknbil, thanks for the response (and sorry for the delay in responding - I'd given up for the day).

Lol, the 'selected' tag was on all the options because I was lazy when preparing this post and just cut 'n' pasted the first line.

You were right about it being a PHP problem. I stripped the page right down to the basics and started again and yes, it did jump ok. I had thought it was only updating a small area of the page and I wasn't sure how to reference that area, but it turns out that it was effectively building a whole new page, so that was much easier to deal with.

I'll certainly give that code of yours a whirl, so thanks again for your time and suggestions. Much appreciated.


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members