I would say first retrieve all the options into an array and then push the one one you want into the array there after push all of the array items into the select again as a dynamic select object Regards, Bongani T Mabunda... Thanks
-----Original Message----- From: Phil Petree <[email protected]> Sender: [email protected] Date: Tue, 7 Jun 2011 16:09:03 To: <[email protected]> Reply-To: [email protected] Subject: [Proto-Scripty] how-to add <option> to <select> 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 [email protected]. To unsubscribe from this group, send email to [email protected]. 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
