Monday, March 30, 2009

Append a data at the end of html select tag

//append at the end of select

function addKeyword()
{
var k = document.getElementById("word").value;//get the data from a text filed
var elOptNew = document.createElement('option');
elOptNew.text = k ;
elOptNew.value = k ;
var elSel = document.getElementById("words");//words is the html select control id
try {
elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
}
catch(ex) {
elSel.add(elOptNew, elSel.selectedIndex); // IE only
}
}

No comments: