Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

Javascript - Option box tag

  • Please log in to reply




  • Member
  • PipPip
  • 15 posts
Hi, I'm not familiar with javascript or html enough to know if this is possible. Please give me some pointers.

Basically I have an option box and I want it to display the value when I click on it. The tricky part is that I want each option to store two values. Something like this:

<select name="Choices" onChange="displayStuff()">
   <option value="apple" myType="fruit" >Apple
   <option value="orange" myType="fruit" >Orange
   <option value="carrot" myType="veggie" >Carrot

in my JavaScript, I try to extract the 'myType' value by this:
function displayStuff() {
   box = document.formname.Choices;
   curType = box.options[box.selectedIndex].myType;

The above code works in IE, but not with Mozilla Firefox.
In Firefox this line: box.options[box.selectedIndex].myType gives me "undefined".

I think it might be because I was a little bit cheating when I added the "myType" tag since it's not a standard tag. Do you know how I can get around the issue? (custom taglib is not an option) Is there a way to store 2 values in 1 selection in the option box? Or can I store the extra information in some kind of hidden fields?

Thanks in advance!
  • 0


Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP