Jump to content

Recommended Posts

Posted

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>

Posted

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.

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

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?

Posted

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

Actualy, the first part isn't a question. And i downloaded a javascript console for firefox, it did not come across any erros, but that could mean that it is not being called.

Posted

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.

Posted
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

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

Posted

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;

Posted

As I described above, you simply give any HTML element an "id" attribute and then call the document.getElementById(string) method, which returns a Javascript "Element" object.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...