Development| HTML| JavaScript| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
JavaScript add method 
 

The add() method is used to add an option to a dropdown list. Here in this example we have added an option to the select tag by using the add() method.

 

JavaScript add method

                         

The add() method is used to add an option to a dropdown list. Here in this example we have added an option to the select tag by using the add() method.

Syntax:

 Object_of_select.add(option,before);

option : it is the option value which is to be added into the select tag's option list and this argument is required.

before : it specifies the position of the option value to be added and it is also required while adding some option to the select tag option.

Description of example:

Here in this example we have created a dropdown list in HTML and we have added a button which will add one more option to the select tag's. This button is calling JavaScript function addNew() and will add an option by getting the select tag element object by using the method getElementById().  

<html>
  <head>
    <script type="text/javascript">
	function addNew(name,val){
	  var opt = new Option(name, val);
	  document.getElementById("myselect").add(opt,undefined);
	}
     </script>
  </head>
  <body>
     <select id="myselect">
	<option value="1">Vineet</option>
	<option value="2">Sandeep</option>
	<option value="3">Vinod</option>
	<option value="4">Amar</option>
     </select>
     <button onClick="addNew('Kumar','5');this.disabled=true;">
       Add
     </button>
  </body>
</html>

Output:

When you will run this HTML page on the browser you will see that it contains only four elements into it.

Now when you will click on the "Add" button it will add one more option to the list named with the "kumar" at the "5" position.

Download Source Code

                         

» View all related tutorials
Related Tags: java javascript c attributes script reference object method sed remove ip attribute node move nat to ref e it alter

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.