Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macaddict23

macrumors 6502
Original poster
Jun 20, 2006
382
1
MacVille, USA
Code:
<form id="form2" name="form2" method="post" action="">
  <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
<option>Find a Dealer</option>
<option value="http://www.somelink.com">Dealer 1</option>
<option value="http://www.somelink.com">Dealer 2</option>
<option value="http://www.somelink.com">Dealer 3</option>
<option value="http://www.somelink.com">Dealer 4/option>
</select>
</form>

1) My client clicks on Dealer 1, and he's taken to another site.
2) He hits the back button, and selects "Find a Dealer" from the list and he's taken to a "Page Not Found".

Sure, it's a "learned behavior" not to click on "Find a Dealer", but the fact is he did, and he was confused. My question is, I didn't specify a value for "Find a Dealer", so I don't understand why he's taken to a page that doesn't exist. I've tried putting a value of <option value=""> and <option value="#"> but I'm taken to the top of the current page, which I don't want because this menu is way at the bottom of the page. Sure, I can probably add anchors, but I'm trying to avoid that. It seems like it's a quick-fix.

Any clues? Thanks in advance!
 

notnek

macrumors 6502
Oct 25, 2007
327
0
I had a form with a similar subject. Mine was Select A School, and the rest of the options were the names of school's. I found it best to use PHP to decide where to send the user.

<?php

$dealer=$_POST['dealer'];

if($dealer=="Find A Dealer"){
header("Location: LINK BACK TO FORM");
}
elseif($dealer=="Dealer 1"){
header("Location: LINK TO DEALER 1");
}
?>

If they select find a dealer, you could echo something like "You must select a dealer" then you could repeat the form or provide a link back.

Just add a name attribute to each option, then create a page with this code, and have the form send to the new page. Make sure to name the select "dealer" or whatever you have post in the PHP.
 

EvanLugh

macrumors 68000
Aug 29, 2007
1,929
2
Developer land
Not to do with your problems but;
<form id="form2" name="form2" method="post" action="">
<select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
<option>Find a Dealer</option>
<option value="http://www.somelink.com">Dealer 1</option>
<option value="http://www.somelink.com">Dealer 2</option>
<option value="http://www.somelink.com">Dealer 3</option>
<option value="http://www.somelink.com">Dealer 4/option>
</select>
</form>
 

macaddict23

macrumors 6502
Original poster
Jun 20, 2006
382
1
MacVille, USA
Good catch Evanlugh. I actually just made a mistake when I copied my source code. I'm still having the same issue. Basically, I don't want "Find a Dealer" to do anything.
 

EvilDog

macrumors newbie
Mar 11, 2008
11
0
Thanks for the help guys. I found the solution.

<option value="" disabled="disabled">Find a Dealer</option>

Not to rain on your parade but that won't work in IE 6.0 . . .

You should wrap the linking action that is part of the function MM_jumpMenu into an if() statement, like this . . .

function MM_jumpMenu(parent,linkValue,num)
{
if (document.getElementById('jumpMenu').selectedIndex > 0)
{
//code that activates the jump link goes here
}
}

What this will do is to only activate the jump link if the user has selected an option other than the first one in the list. This will guarantee that it works in all browsers.

One other thing and that is where you have -

onchange="MM_jumpMenu('parent',this,0)"

You may want to change the part where it says this instead -

onchange="MM_jumpMenu('parent',this.value,0)"

This will also help to assure cross browser compatibility.

Hope this helps . . . :cool:
 

Yvan256

macrumors 603
Jul 5, 2004
5,081
998
Canada
A drop-down menu that activates a script on change is not good:
- people using the keyboard to browse won't be able to use that type of navigation.
- people with javascript disabled won't be able to use this either
- good luck with getting indexed with javascript links.

sorry if I sound harsh, it's 02:36... gotta go to bed. ;)
 

macaddict23

macrumors 6502
Original poster
Jun 20, 2006
382
1
MacVille, USA
Not to rain on your parade but that won't work in IE 6.0 . . .

You should wrap the linking action that is part of the function MM_jumpMenu into an if() statement, like this . . .

function MM_jumpMenu(parent,linkValue,num)
{
if (document.getElementById('jumpMenu').selectedIndex > 0)
{
//code that activates the jump link goes here
}
}

I'm not sure what you mean. Can you plug this into my source code above so I have a better idea what you mean? Thanks EvilDog.
 

stndn

macrumors member
Oct 22, 2006
80
1
earth
Here's an option, although this makes the 'Find a dealer' not selectable:
HTML:
<optgroup label="Find a Dealer">
<option value="http://www.somelink.com">Dealer 1</option>
<option value="http://www.somelink.com">Dealer 2</option>
<option value="http://www.somelink.com">Dealer 3</option>
<option value="http://www.somelink.com">Dealer 4</option>
</optgroup>

(I added optgroup for your options)

Btw, why not make the 'Find a dealer' a label, instead? I think that makes better sense....


-stndn.
 

EvanLugh

macrumors 68000
Aug 29, 2007
1,929
2
Developer land
Might just be easier to make it obvious to people
Code:
<select name="select" size="1" id="select">
    <option>--Find a Dealer--</option>
    <option>Dealer 1</option>
    <option>Dealer 2</option>
    <option>Dealer 3</option>
    <option>Dealer 4</option>
  </select>

Code:
<select name="select" size="1" id="select">
    <option>Select a Dealer..</option>
    <option>Dealer 1</option>
    <option>Dealer 2</option>
    <option>Dealer 3</option>
    <option>Dealer 4</option>
  </select>
 

EvilDog

macrumors newbie
Mar 11, 2008
11
0
I'm not sure what you mean. Can you plug this into my source code above so I have a better idea what you mean? Thanks EvilDog.

Well, there must be some javascripting up in the <head> part of your webpage where you will see a function with the name MM_jumpMenu. Either this or it lives in a separate document with a .js file extension that is referenced to by the webpage. Perhaps you can post a link to the page in question and I should be able to assist you further if I can have a look at how everything is laid out.
 

stndn

macrumors member
Oct 22, 2006
80
1
earth
Thanks stndn. Now, how do I make "Find a Dealer" be the default selected item?

Unfortunately, <optgroup>s are not selectable. They are there to group list options only. That's why I suggested having the text label outside the list of options.

If you want to have selectable options which does not become a valid selection, then you'll have to check the user's selections and verify if it's an acceptable option or not. It's more work than worth it so, unless you have specific reason, you should just move the 'Find a dealer' outside.


-stndn.
 

notnek

macrumors 6502
Oct 25, 2007
327
0
An easy way to do this is to use PHP if/elseif to check what they selected. If it's Find A Dealer, you can send them back or show them the form again.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.