As JavaScript's add() method is used to add more option elements to the tag. JavaScript remove method JavaScript remove method As JavaScript's add() method is used to add more option elements to the <select> tag. Similarly we can also remove option elements of the <select> tag by using the method remove() of the JavaScript. Syntax : select_object.remove(selected_index); Where select_object holds the select tag element's reference. Description of code : To illustrate the use of remove() method we have created a simple HTML page into which we have created a dropdown list by using <select> tag and by default it consists of four items. <select id="myselect"> <option value="1">Vineet</option> <option value="2">Sandeep</option> <option value="3">Vinod</option> <option value="4">Amar</option> </select> We have a button "Remove", when clicked calls a JavaScript method "removeItem()" which is defined between the <script> tags. function removeItem(){ var element =document.getElementById("myselect"); element.remove(element.selectedIndex); } The function removeItem() takes the element object and then removes the element.selectedIndex item from the select tag option list. Here is the full example code for removeExampl.html as follows : <html> <head> <script type="text/javascript"> function removeItem(){ var element =document.getElementById("myselect"); element.remove(element.selectedIndex); } </script> </head> <body> <p align="center"> </p> <div style="background: #cf2255; width:'100%';" align="center"> <font color="#ffffcc" size="12pt"> <b>Remove method in JavaScript</b> </font> </div> <center> <div style="background: #ffffcc; width:'100%';" align="center"> <p align="left"> </p> <select id="myselect"> <option value="1">Vineet</option> <option value="2">Sandeep</option> <option value="3">Vinod</option> <option value="4">Amar</option> </select> <input type="button" onClick="removeItem(); this.disabled=true;" value="Remove"> </div> </center> </body> </html> Output : Click on the button "Remove" and it will remove the selected option from the <select> tag option list and if none is selected then by default first item will be removed. In our this example we don't have select any item therefore it removes first option which is "Vineet". As soon as it removes item in the <select> list the button is disabled, this means remove operation have been performed successfully. Download Source Code Older Newer Tutorials JavaScript method doScroll() Popup Window Example in JavaScript JavaScript method deleteRow() JavaScript Variables and Data types Java Script Code of Calendar and Date Picker or Popup Calendar JavaScript - JavaScript Tutorial Looping In Java Script What is JavaScript? - Definition Conditional Examples(if - else- switch case) in JavaScript Classes-Objects in JavaScript String Number Operations in JavaScript Conditions In Java Script JavaScript - JavaScript Tutorial JavaScript Object Oriented Feature Form Validation using Regular Expressions is JavaScript Navigation with Combo box and Java Script Simple Calculator Application In Java Script JavaScript Combo Box Validation JavaScript createPopup method JavaScript appendChild method JavaScript add method JavaScript addImport example JavaScript appendData method JavaScript applyElement method Example JavaScript blink method JavaScript bold method JavaScript clear method JavaScript clearTimeOut method JavaScript click method JavaScript cloneNode example JavaScript createAttribute method JavaScript createCaption method JavaScript createComment method JavaScript createEventObject method JavaScript createTFoot method JavaScript createTHead method JavaScript deleteCaption method JavaScript deleteTFoot method JavaScript deleteTHead method JavaScript dragDrop method Top Tutorials Java Spring Hibernate PHP Struts Advanced Java JSP Servlet Videos Getting Started Java JDBC Encapsulation in Java Spring 3 MVC Hibernate JSP Login Form Our Youtube channel Training Big Data and Hadoop Core Java Hibernate Spring PHP Ajax Struts 2 All Courses... Software Solutions Software Services JSF Development Outsourcing ERP M-Commerce Flex Development Web Development Website Development Web Designing Web Redesigning Web Development Logo Design Web Design Packages Domain Registration SEO Web Promotion Services SEO Services Search Eng. Optimization SEO Tips Web Promotion Plans Content Content Development Article Writing Blog Writing News Writing SEO Copywriting Technical Documentation Article Marketing Hosting Web Hosting Services ASP.NET Hosting Unix Hosting E-Commerce Hosting Windows Hosting Hosting Plan E-Commerce E-Commerce Solutions CRM Copyright © RoseIndia.Net 2022