Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Javascript - Option box tag


  • Please log in to reply

#1
duckie

duckie

    Member

  • 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
</select>

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

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

Advertisements







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