Click to See Complete Forum and Search --> : add option


crs
05-22-2003, 05:59 AM
It's me again with Mozilla and Opera problems. :(

This code works fine on IE, but I would lke it to work on "non IE" too.

<html>
<head>
<title>Option Test</title>
<script>
function init()
{
myobject=document.createElement("OPTION");
myobject.value="Test Value";
document.myform.elements['ul'].add(myobject);
document.myform.ul.lastChild.innerText="Test Text";
}
</script>
</head>

<body onload="init()">

<form name="myform">
<select name="ul"></SELECT>
</form>
</body>
</html>

Thank you in advance...

crs
05-22-2003, 06:29 AM
I have found a way :)

It is...

<html>
<head>
<title>Option Test</title>
<script>
function init()
{
myobject=document.createElement("OPTION");
myobject.value="2";
document.myform.ul.appendChild(myobject);
myobjecttext=document.createTextNode("2");
myobject.appendChild(myobjecttext);
}
</script>
</head>

<body onload="init()">

<form name="myform">
<select name="ul"></SELECT>
</form>
</body>
</html>