Jump to content

dropdown menu javascript


Recommended Posts

me and my freind are trying to get this code working, it is supposed to be a drop-down select box, once you choose an option it will take you to the page you selected.

 

<html>
<head><script LANGUAGE="JavaScript">
function formHandler{
var URL = document.form.site.options[document.form.site.selectedIndex].value;
location.href = URL;
}
</SCRIPT>
</head>
<body>
<form name="form">
<select name="site" size=1 onchange="formhandler()">
<option value="">Go to...</option>
<option value="http://anime-dungeon.com/blog">Blog</option>
<option value="http://anime-dungeon.com/forum">Forum</option>
<option value="http://theotaku.com/worlds/dungeonsend">Dungeons End</option>
</select>
</form>
</body>
</html>

Link to comment
Share on other sites

djbob, it's not working ;)

 

<select name="site" size=1 onchange="formhandler()">

From what I can tell, formHandler() needs to have the proper capitalization, javascript is case sensitive.

That's just at a first glance though, g'luck.

Link to comment
Share on other sites

djbob, it's not working ;)
"Not working" is rather vague. There could be an error message (as in this case I'm sure there was), which would greatly ease debugging. The code could work partly, but break at a certain point. It could run without an error, but not produce the intended functionality.
Link to comment
Share on other sites

Most browers hide Javascript errors by default. In IE, look at the lower left corner for Javascript errors. Double click the message if there is one. For FF, there is a Javascript Console in the Tools menu or something.

 

So did changing the capitalization fix the issue?

Link to comment
Share on other sites

Try capitalizing the first letter in your sentences and using periods. Also, make sure to reply to all parts of someone else's post.

 

In IE, look at the lower left corner for Javascript errors. Double click the message if there is one. For FF, there is a Javascript Console in the Tools menu or something.
Link to comment
Share on other sites

So is onchange an actual event? I've never heard of it. *Looks on w3schools*

Got it.

Okay, so your script is horribly outta whack. You need to use the id attribute if you want it to work. I'm pretty sure document.form won't work.

You'll also have to find some way to pass the url of where you want the browser to go to the function, instead of defining that in the function.

Link to comment
Share on other sites

so is onchange an actual event? I've never heard of it. *Looks on w3schools*

Okay, so your script is horribly outta whack. You need to use the id attribute if you want it to work. I'm pretty sure document.form won't work.

how do you propose the code should be written, i've never heard of the ID attribute

Link to comment
Share on other sites

I'm pretty sure document.form won't work.
It actually should.

 

i've never heard of the ID attribute
Any HTML element can have an ID, ie. <input type="text" name="textfield" id="textfield">

It can then be called in Javascript by the getElementById function, like so: document.getElementById("textfield")

 

I'm not sure why your way isn't working, though. Try with any browser, perhaps?

Link to comment
Share on other sites

tried with...

firefox: drop down appeared, but does nothing

ie: same

ie 64 bit: same

 

i don't have either opera or safari but i doubt if the gecko 3 engine (the heart of firefox) can't run it, anything else could.

 

how would i get the value for an ID

 

var URL = document.[the ID from form].[the id from site].options[document.[the ID from form].[the id from site].selectedIndex].value;

Link to comment
Share on other sites

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.   Paste as plain text instead

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