simonchristieis
Programmer
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="numbers">
<option>1</option>
<option>2</option>
</select>
<input type="button" onclick="create()">
</form>
anyone wanna help?
simon
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="numbers">
<option>1</option>
<option>2</option>
</select>
<input type="button" onclick="create()">
</form>
anyone wanna help?
simon