Closed Thread Icon

Topic awaiting preservation: Using onChange in an HTML dropdown menu Pages that link to <a href="https://ozoneasylum.com/backlink?for=26222" title="Pages that link to Topic awaiting preservation: Using onChange in an HTML dropdown menu" rel="nofollow" >Topic awaiting preservation: Using onChange in an HTML dropdown menu\

 
Author Thread
Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 07-12-2005 14:19

Hello there, it's me, the resident JS idiot. I'll try to be brief this time. The HTML code:

code:
<form name="schemes">
               <select name="scheme" size="1">
                    <option value="lanterns">Lanterns</option>
                    <option value="coastal">Coastal</option>
                    <option value="buddha">Buddha</option>
                    <option value="osanri">Osan-ri</option>
               </select>
          </ form>



Just a plain HTML dropdown menu. What I want to do is use onChange to activate the style switching mechanism. Every resource I have found on the internet accesses the value of the selected option with this: this.options[this.selectedIndex].value

I tried to incorporate this in the code above, coming up with this:

[/code]
<form name="schemes" onChange="setStyle(this.options[this.selectedIndex].value); return false;">
[code]

setStyle(), of course is the JS end of my style-switching mechanism. It works fine with straight-up links, but I'm having problems getting it to work with this dropdown menu. I know the function itself works with onChange in FF, as I tested it by replacing the "this.options..." part with a plain old variable (just like I have in the links I currently use, i.e.: "setStyle('lanterns'); return false;") and it works fine. The JS for accessing the selected option doesn't seem to work at all. Even worse, onChange doesn't appear to work at all in IE--it doesn't respond to even the straight test case that works in FF.

So, I'm stumped. From what I've seen, a lot of people use this technique and it seems to work fine. What is it with me and JS? Why am I such a freaking idiot?

OK, the answer to that last question in particular is probably too long for this forum, but does anyone have any idea of what might be going wrong here? Let me know if you need more information.

So much for brief.

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup

Moobie
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Jul 2005

posted posted 07-12-2005 14:57

I think you just got the wrong element:

code:
<form name="schemes">
	<select name="scheme" size="1" onchange="setStyle(scheme.options[this.selectedIndex].value)">
		<option value="lanterns">Lanterns</option>
		<option value="coastal">Coastal</option>
		<option value="buddha">Buddha</option>
		<option value="osanri">Osan-ri</option>
	</select>
</form>

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 07-12-2005 16:54

Unbelievable. I should really stop trying to code when tired. My brain just doesn't work like it used to.

Thanks. Oh, and welcome to the Asylum. I'm not usually this stupid (no comments from the peanut gallery, thank you).

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup

Moobie
Obsessive-Compulsive (I) Inmate

From: UK
Insane since: Jul 2005

posted posted 07-12-2005 17:12

No sweat.

« BackwardsOnwards »

Show Forum Drop Down Menu