-
I want to use a sleect option html box just liek a list box in VB. Is this possible?
What i am trying to accomlish is to have a list of things and to be able to add or delete items depending on button presses.
I dont know how to manipulate the select box this way.
this is my code so far:
<SELECT NAME="items" SIZE=5>
<OPTION>Windows</option>
<OPTION>Macintosh</option>
<OPTION>UNIX</option>
</SELECT>
and i have two buttons, one is an add button which when pressed brings up a prompt and when a user enters infor it should appear in the above select box.
the delete button shoudl casue the selected item in the above box to be elimanted.
If i can't do this in JAvaScript, any suggestons on how to do it? Thanks.
-
That could be really easily done if you could use ASP and a database. Can you use this technology?
-
not quite it must be done wiht java script since i am putting it on my desktop wiht active desktop.
I found a good solution on my own though:
http://htmlgoodies.earthweb.com/tutors/ifthis.html
check it out if anyone has this same problem
-
Code:
<HTML>
<HEAD>
<script language=javascript>
function addItem()
{
var oOption;
var strTemp = prompt("Enter new item")
oOption = document.createElement("OPTION");
oOption.text=strTemp;
document.frm1.items.add(oOption);
}
function removeItem()
{
var i = document.frm1.items.selectedIndex;
document.frm1.items.options[i] = null;
}
</script>
</HEAD>
<BODY>
<form name=frm1>
<SELECT NAME="items" SIZE=5>
<OPTION>Windows</option>
<OPTION>Macintosh</option>
<OPTION>UNIX</option>
</SELECT>
<br>
<input type=button value="Add Item" onClick="addItem()">
<input type=button value="Remove Item" onClick="removeItem()">
</form>
</BODY>
</HTML>
-
I'm glad you found an answer, and Mark has a good one, too.
As to the suggestion of ASP. You could use that approach if you wanted the menu to be populated server side. Since you want it dynamicaly altered on the client side, you must use a client side technology, such as JavaScript (or JScript).