PDA

View Full Version : Dynamic creation of drop-down list


gblair
10-11-2002, 08:53 PM
What I would like to do is to dynamically (on button click) create a select element in a particular column/row in a table. The other question I have is: is it possible to dynamically change the type of an element on-the-fly? The scenario would be having a text object that the user enters search terms into; however, if a certain button is clicked, this text object would become a drop-down list populated with keywords. I would be very appreciative of any help with either of these questions.

Thank you.

beetle
10-11-2002, 09:34 PM
Well, check this out first...<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">
function addOption(f, sID, val, label) {
var o = document.createElement("OPTION");
var t = document.createTextNode(label);
o.appendChild(t);
o.value = val;
f.elements[sID].appendChild(o);
}
</script>
</head>
<body>
<form>
<input type="text" name="date">
<input type="button" value=">>>" onClick="addOption(this.form,'vac_black',this.form.date.value, this.form.date.value)">
<select size="2" name="vac_black"></select>
</form>
</body>
</html>Mess around with it...see if you can get it to add options to the SELECT item you chose...