Your function is using add() to add an option to the end of the
select, but I have never seen that work completely myself. Best to
stick with the long-hand methods, they are at least known to work in
most browsers:
menu = $('mySelectList');
menu.options[menu.options.length] = new Option('Label','value');
Walter
On Jun 7, 2011, at 4:09 PM, Phil Petree wrote:
I've tried every option that I can find or figure out to add an
<option> to a <select> using prototype or dom.
What I have figured out is that when prototype 1.6.x is present
normal dom functions dont SEEM work!
??? So how do you add an option to a select in prototype? ???
I have:
var value = "New York"; // json.options[i].value
var display = "New York"; // json.options[i].text
I have tried:
$('city').options[i] = new Option(json.options[i].text,
json.options[i].value, null,(sel&&sel==json.options[i].value?
true:false));
$('city').add = new Option(display, value);
addOption('city', value, display);
addOption('city', "New York", "New York");
select.insert(new Element('option', {value: value}).update('city'));
// and about a dozen other options
// this function works if called from the form with
onclick="addOption('city', 'New York', 'New York')">
// but if called from the onSuccess function and being passed the
data (or even hard coded) I get nothing!
function addOption(selectID, value, display)
{
var myselect = document.getElementById(selectID);
try
{
myselect.add(new Option(display, value), null); //add new option
to end of selectID
}
catch(e)
{
//in IE, try the below version instead of add()
myselect.add(new Option(display, value)); //add new option to
end of selectID
}
}
--
You received this message because you are subscribed to the Google
Groups "Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
.
To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com
.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en
.
--
You received this message because you are subscribed to the Google Groups "Prototype
& script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en.