Adding and Deleting Menu Select Items

[Total: 0    Average: 0/5]

This example shows you how to add and delete items in a form select menu.

Head Code:

<script>
function add() {
var newitem=prompt("Add New List Item","");
document.form.list[document.form.list.length] = new Option(newitem, document.form.list.length);
}
function del() {
if (document.form.list.selectedIndex >= 0) {
document.form.list.options[document.form.list.selectedIndex]=null;
document.form.list.selectedIndex=0;
}
}
</script>

Body Code:

<center>
<form name="form">
<select name="list" size="10">
<option>List Item #1
<option>List Item #2
<option>List Item #3
<option>List Item #4
</select>
<p><input type="button" value="Add" onClick="add()"> <input type="button" value="Del" onClick="del()">
</form>
</center>

Times Viewed: 4

Leave a Reply

Your email address will not be published. Required fields are marked *