Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create dynamic select box optgroup

Status
Not open for further replies.

simonchristieis

Programmer
Jan 10, 2002
1,144
GB
I am trying to craete a dynamic optgroup for a select box:

the closest ive managed is to create the optgroup but not add any options to it.

function create(){
var optGroup = document.createElement('optgroup')
var objSelect=document.forms(0).elements(0);
var objOption=document.createElement("option")

objOption.text = "test"
objOption.value = "simon"

optGroup.label = "simple"

objSelect.appendChild(optGroup)
optGroup.appendChild(objOption)
}

<form>
<select>
<optgroup label=&quot;numbers&quot;>
<option>1</option>
<option>2</option>
</select>
<input type=&quot;button&quot; onclick=&quot;create()&quot;>
</form>


anyone wanna help?

simon
 
i forgot to say what the problem was - the optgroup is being created but the is no text for the created option.
 
See thread215-769111

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

 
Just saw it - when creating new options i use

.text

but this only works with

.innerHTML

Congratulations!

Star for you





 
CSS enthusiasts might want you to create a textNode and append it, but the innerHTML is the easiest...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top