crazybmanp Posted August 19, 2008 Posted August 19, 2008 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>
Wizard Posted August 19, 2008 Posted August 19, 2008 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.
crazybmanp Posted August 19, 2008 Author Posted August 19, 2008 o, i forgot javascript is case sensitive, i will see if that fixes it
Ashoat Posted August 19, 2008 Posted August 19, 2008 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.
crazybmanp Posted August 19, 2008 Author Posted August 19, 2008 actually, it doesn't work is pretty much what it is doing. the form produces the drop-down box, but when you change it, nothing happens.
Ashoat Posted August 19, 2008 Posted August 19, 2008 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?
Ashoat Posted August 19, 2008 Posted August 19, 2008 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.
crazybmanp Posted August 19, 2008 Author Posted August 19, 2008 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.
Wizard Posted August 20, 2008 Posted August 20, 2008 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.
crazybmanp Posted August 20, 2008 Author Posted August 20, 2008 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
Ashoat Posted August 20, 2008 Posted August 20, 2008 I'm pretty sure document.form won't work.It actually should. i've never heard of the ID attributeAny 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?
crazybmanp Posted August 20, 2008 Author Posted August 20, 2008 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;
Ashoat Posted August 20, 2008 Posted August 20, 2008 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now