tuzojazz Posted January 30, 2008 Share Posted January 30, 2008 Hi:how can I remove drop-down box items?Thanks! Link to comment Share on other sites More sharing options...
Ingolme Posted January 30, 2008 Share Posted January 30, 2008 A dropdown box is made of <select> and <option> tags.What you need to do is access the option nodes based on, for example, their value.Here's an example:I'm going to delete the option tag with value "option2"HTML<select id="something"><option value="option1">Option</option><option value="option2">Option</option><option value="option3">Option</option></select>JavaScript N = document.getElementById("something"); //Get the dropdown boxfor(x=0;x<N.getElementsByTagName("option").length;x++) {// Loop through the dropdown box items if(N.getElementsByTagName("option")[x].value == "option2") { N.removeChild(N.getElementsByTagName("option")[x]); }} Link to comment Share on other sites More sharing options...
tuzojazz Posted January 30, 2008 Author Share Posted January 30, 2008 A dropdown box is made of <select> and <option> tags.What you need to do is access the option nodes based on, for example, their value.Here's an example:I'm going to delete the option tag with value "option2"HTML<select id="something"><option value="option1">Option</option><option value="option2">Option</option><option value="option3">Option</option></select>JavaScriptN = document.getElementById("something"); //Get the dropdown boxfor(x=0;x<N.getElementsByTagName("option").length;x++) {// Loop through the dropdown box items if(N.getElementsByTagName("option")[x].value == "option2") { N.removeChild(N.getElementsByTagName("option")[x]); }} thanks my friend!! it works!! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.