questions about SELECT and innerHTML

D

datactrl

I tried to do this to change the OPTION part of a SELECT.

cust.innerHTML = "<option value='AAA'>AAA</option><option
value='BBB'>BBB</option><option value='CCC'>CCC</option><option
value='DDD'>DDD</option><option value='EEE'>EEE</option>";

It won't work at all. After tracing a while, I found it became like ...

AAA</option><option value='BBB'>BBB</option><option
value='CCC'>CCC</option><option value='DDD'>DDD</option><option
value='EEE'>EEE</option>

in the OPTION part of that SELECT. Is there anything wrong? Or it's the way
it should be. And is there any work aorund?

Jack
 
M

Martin Honnen

datactrl said:
I tried to do this to change the OPTION part of a SELECT.

cust.innerHTML = "<option value='AAA'>AAA</option><option
value='BBB'>BBB</option><option value='CCC'>CCC</option><option
value='DDD'>DDD</option><option value='EEE'>EEE</option>";

There have always been other APIs to add/remove options from a <select>
element for instance since Netscape 3
selectElement.options[selectElement.options.length] =
new Option('text', 'value')
to add an option and
selectElement.options[someIndex] = null
to remove an option.
You can also since IE5 and Netscape 6 or with other DOM compliant
browsers use the DOM to create and insert or to remove options.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top