Total members 11894 |It is currently Thu Nov 21, 2024 6:37 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Add new option to select dynamically
javascript code
<html>
<head>
<title>Add new option to select dynamically </title>

<!--
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
Note you can download the JQuery package instead of using Google version. -->
<script src="jquery-1.8.3.js"></script>
<script>
$(document).ready(function(){
$("input#btnAdd").click(function(){

alert($('#newOption').attr('value'));
$('#MyOptions').append(new Option($('#newOption').attr('value'), $('#newOption').attr('value'), true, true));
//newOption

});
});
</script>

<style type="text/css">
#MyOptions
{
font-weight:bold;
background:#1C32F1;
visibility:visible;
text-align:center;
text-decoration: underline;
color:yellow;
}
</style>

</head>

<body>
<p>Add new option when you click on the button below:</p>

<input type="button" value="Add opition" id="btnAdd" />: Country to add: <input type="text" id="newOption" />


<select id="MyOptions">
<option></option>
<option value="France">France</option>
<option value="USA">USA</option>
<option value="Canada">Canada</option>
</select>
</body>
</html>




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Change the content of select tag using JQuery
 Load Content to Tabs using AJAX and JQuery     -  
 Change and get html content of element     -  
 Load file and update content using AJAX and JQuery     -  
 Cant change the culture or UICulture of the content page     -  
 Change CSS Properties from JQuery     -  
 select query example in php     -  
 Select odd rows from table     -  
 Select all links with a target attribute value NOT _blank     -  
 Javascript select menu validation issue     -  
 Javascript Validation On Multiple Select Lists     -  



Topic Tags

JQuery Validation






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com