<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Web Effects Dynamic Change Select value </title>
<script language= "JavaScript" >
var getselectvalue = funtion (select)
{
var idx = Select.selectedindex,
Option
Value
if (idx >-1) {
option = Select.options[idx];
value = Option.attributes.value;
Return (value && value.specified)? Option.value:option.text);
}
return null;
}
</script>
<body>
<script type= "Text/javascript" >
var getselectvalue = function (select) {
var idx = Sele Ct.selectedindex,
option,
value;
if (idx >-1) {
option = Select.options[idx];
value = Option.attributes.value;
Return (value && value.specified)? Option.value:option.text;
}
return null;
}
</script>
<select id= 111cnnet "onchange=" alert (getselectvalue document.getElementById (' 111cnnet ')) >
<option value= "http://www.111cn.net" > Web page Making Tutorials </option>
<option value= "http ://mb.111cn.net > Templates </option>
</select>
</body>
Other details about the Web page special Select,
1. Determine if there is a value= "Paravalue" Item in the Select option
function Web Effects Selectisexititem (objselect, Objitemvalue) {
var isexit = false;
for (var i = 0; i < objselect.options.length; i++) {
if (Objselect.options[i].value = = Objitemvalue) {
Isexit = true;
Break
}
}
return isexit;
}
2. Add an item to the Select option
function Jsadditemtoselect (Objselect, Objitemtext, Objitemvalue) {
To determine whether there is
if (Jsselectisexititem (Objselect, Objitemvalue)) {
Alert ("The value of the item already exists");
} else {
var varitem = new Option (Objitemtext, Objitemvalue);
Objselect.options.add (Varitem);
Alert ("Join successfully");
}
}
3. Remove an item from the Select option
function Jsremoveitemfromselect (Objselect, Objitemvalue) {
To determine whether there is
if (Jsselectisexititem (Objselect, Objitemvalue)) {
for (var i = 0; i < objselect.options.length; i++) {
if (Objselect.options[i].value = = Objitemvalue) {
Objselect.options.remove (i);
Break
}
}
Alert ("Successful deletion");
} else {
Alert ("The item does not exist in the select");
}
}
4. Delete selected items in select
function Jsremoveselecteditemfromselect (objselect) {
var length = objselect.options.length-1;
for (var i = length; I >= 0; i--) {
if (objselect[i].selected = = True) {
Objselect.options[i] = null;
}
}
}