By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

Problem whit <SELECT>

P: n/a
How can I add <OPTION> to a tag <SELECT> runtime ?

the code combo.innerHTML+="<OPTION value='1'>Name</OPTION>" doesn't
work...
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Cristian Martinello" <ca*********@tiscali.it> writes:
How can I add <OPTION> to a tag <SELECT> runtime ?

the code combo.innerHTML+="<OPTION value='1'>Name</OPTION>" doesn't
work...


"Doesn't work" is not very useful as an error message.

What browsers must it work in? You use the proprietary "innerHTML".

I assume "combo" refers to the select element. In that case, this is
the most portable method:

combo.options[combo.options.length]=new Option("Name","1");

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a


Cristian Martinello wrote:
How can I add <OPTION> to a tag <SELECT> runtime ?

the code combo.innerHTML+="<OPTION value='1'>Name</OPTION>" doesn't
work...


var option = new Option('text', 'value');
combo.options[combo.options.length] = option;

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3

P: n/a

I works only in IE and I use:
newOpt = document.createElement("option");
newOpt.text="This is the new option text"
newOpt.value="newOptionValue"

document.formName.SelectName.options.add(newOpt,2) ;

2 is the location of added option on the select.
<select name="SelectName">
<option value="0" selected>Configuration file</option>
<option value="1" selected>Test file</option>
</select>

Good luck,

Yaron
On Wed, 15 Oct 2003 15:15:20 +0000 (UTC), "Cristian Martinello"
<ca*********@tiscali.it> wrote:
How can I add <OPTION> to a tag <SELECT> runtime ?

the code combo.innerHTML+="<OPTION value='1'>Name</OPTION>" doesn't
work...


Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.