Clever "add tag" javascript help needed

Posted by Camran on Stack Overflow See other posts from Stack Overflow or by Camran
Published on 2010-05-17T15:22:17Z Indexed on 2010/05/17 16:10 UTC
Read the original article Hit count: 252

Filed under:
|
|

I have this function for adding options to a Select list:

 function addOption(selectbox, value, text, cl )
 {
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
if (cl==1){ optn.className = "nav_option_main"; }
selectbox.options.add(optn);
 }

I have just discovered the "optgroup" tag, but I don't know how to implement it to the drop list.

The function above is called on another selectboxes "OnChange" event, to fill sub-select-box with the desired options.

I don't think it should be too difficult to add the "optgroup" tag into this, or is it?

Thanks and if you need more input let me know...

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html