Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
119
rated 0 times [  123] [ 4]  / answers: 1 / hits: 22006  / 15 Years ago, tue, january 26, 2010, 12:00:00

I want a to add an option dynamically to a Select element using Prototype.


There seems to be a lot of different ways to do it out there, all to do with options.add etc... Not seen much in the way of cross-browser ways.


Want it to be as lightweight as possible.


This is what I have got so far. It's just the appending the options that I'm stuck on:


var oNewOption = new Element('option').value=vItem;
oNewOption.text=vItem;

Any ideas anyone?


More From » select

 Answers
12
select.insert(new Element('option', {value: myValue}).update(myLabel));


insert appends to the content of the select object, update updates the content of the new option object.



Not really better than the classic way, though.


[#97745] Friday, January 22, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
isham

Total Points: 69
Total Questions: 86
Total Answers: 86

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
;