Results 1 to 5 of 5

Thread: JavaScript Listbox type problem

  1. #1
    dmartin17
    Guest
    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.

  2. #2
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    That could be really easily done if you could use ASP and a database. Can you use this technology?

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  3. #3
    Guest
    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

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    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>
    Mark
    -------------------

  5. #5
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    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).
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width