var o=document.getElementById('selectItem'); var s="test" for(var i=0;i<o.options.length;i++){ if(o.options[i].value==s){ alert('exsisted!');return } }
function addToSelect(value) { var opts = document.getElementById('selectItem').options; for(var i=0, n=opts.length; i<n; i++){ if(opts[i].value == value) return; } var opt = document.createElement("OPTION"); opt.value = value; opt.innerText = value; opts.add(opt); }
<input type="text" id="AreaName" name="AreaName" class="input_blue" maxlength="63" size="14"><select name="selectItem" style="z-index: 102; left: 264px; width: 165px;" id="selectItem" multiple="" size="5"><option value="DDDDD">DDDD</option></select><input type="button" src="../../../img/button_next.gif" value="增加" onclick="fun()"> <SCRIPT LANGUAGE="JavaScript"> <!-- function fun(){ var AreaName = document.getElementById("AreaName"); var selectItem = document.getElementById("selectItem"); if (AreaName.value) { for (var i=0; i<selectItem.options.length; i++) { if (selectItem.options[i].value == AreaName.value) return; } var opt = document.createElement("option"); opt.value = opt.innerHTML = AreaName.value; selectItem.appendChild(opt); } } //--> </SCRIPT>
var s="test"
for(var i=0;i<o.options.length;i++){
if(o.options[i].value==s){ alert('exsisted!');return }
}
function addToSelect(value) {
var opts = document.getElementById('selectItem').options;
for(var i=0, n=opts.length; i<n; i++){
if(opts[i].value == value) return;
}
var opt = document.createElement("OPTION");
opt.value = value;
opt.innerText = value;
opts.add(opt);
}
<input type="text" id="AreaName" name="AreaName" class="input_blue" maxlength="63" size="14"><select name="selectItem" style="z-index: 102; left: 264px; width: 165px;" id="selectItem" multiple="" size="5"><option value="DDDDD">DDDD</option></select><input type="button" src="../../../img/button_next.gif" value="增加" onclick="fun()">
<SCRIPT LANGUAGE="JavaScript">
<!--
function fun(){
var AreaName = document.getElementById("AreaName");
var selectItem = document.getElementById("selectItem");
if (AreaName.value)
{
for (var i=0; i<selectItem.options.length; i++)
{
if (selectItem.options[i].value == AreaName.value) return;
}
var opt = document.createElement("option");
opt.value = opt.innerHTML = AreaName.value;
selectItem.appendChild(opt);
}
}
//-->
</SCRIPT>