SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot contactnaveen's Avatar
    Join Date
    Oct 2004
    Location
    India
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Multiple Select Box

    How to retrieve the values of multiple select box in JSP.

    This is what i did to retrieve values in Javascript, but i dont know how to get values in JSP:

    <HTML>
    <HEAD>
    <SCRIPT>
    function getSelectedValues (select) {
    var r = new Array();
    for (var i = 0; i < select.options.length; i++)
    if (select.options[i].selected)
    r[r.length] = select.options[i].value;
    return r;
    }
    </SCRIPT>

    <BODY>
    <SELECT NAME="select2" MULTIPLE ONCHANGE="alert('Now selected: ' + getSelectedValues(this))">
    <OPTION VALUE="test1">Sample1
    <OPTION VALUE="test2">Sample2
    <OPTION VALUE="test3">Sample3
    <OPTION VALUE="test4">Sample4
    </SELECT>
    </BODY>

    </HTML>

    Thanx in advance

    Regards,
    Naveen. V

  2. #2
    SitePoint Addict dek's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never used JSP, but you could shorten your Javascript some.

    Code:
     result = select.options[select.selectedIndex].value;
    Only dead fish go with the flow

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JSP is Java, not JavaScript.

    You would need to put the <select> in a <form> and then submit it, so your JSP script could process it.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

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