www.webdeveloper.com
Results 1 to 4 of 4

Thread: Using javascript to retrieve selected items in a listbox

Hybrid View

  1. #1
    Join Date
    Apr 2007
    Posts
    2

    Using javascript to retrieve selected items in a listbox

    Hello - I need to retrieve selected items in a multi select listbox using javascript. I am using asp.net 2.0 and using callbacks. I have two dropdownlists and a listbox in a cascade. When I click the submit button I need to read the values of the controls using javascript which will then run a sub-routiine in the code behind that queries the database and binds the gridview.

    Thanks,

    Rick

  2. #2
    Join Date
    May 2003
    Location
    Between Baltimore and DC
    Posts
    3,579
    How is JavaScript running serverside code? Ajax?

    Code:
      var sel = document.getElementbyId("ddlId");
      var optsLength = sel.options.length;
      for(var i=0;i<optsLength;i++){
        if(sel.options[i].checked)alert(sel.options[i].text);
      }
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint] | twitter | linkedin | http://www.pascarello.com

  3. #3
    Join Date
    Apr 2012
    Posts
    1
    Quote Originally Posted by A1ien51 View Post
    How is JavaScript running serverside code? Ajax?

    Code:
      var sel = document.getElementbyId("ddlId");
      var optsLength = sel.options.length;
      for(var i=0;i<optsLength;i++){
        if(sel.options[i].checked)alert(sel.options[i].text);
      }
    Eric
    Thank you Eric your code was really useful for me, you did a little mistake options can be selected and not checked

    Code:
      var sel = document.getElementbyId("ddlId");
      var optsLength = sel.options.length;
      for(var i=0;i<optsLength;i++){
        if(sel.options[i].selected)alert(sel.options[i].text);
      }

  4. #4
    Join Date
    Apr 2007
    Posts
    2
    Thanks for the code.
    Serverside code is run via asynchronous callbacks. Using Microsoft's System.Web.UI.ICallbackEventHandler class

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles