Posted By

mattvbiggs on 03/02/13



Versions (?)

jQuery: Double Click to Add

 / Published in: jQuery

The snippet below was pulled from code that loads a list of names pulled from Active Directory into a listbox. This code will execute when the user double clicks on a name in the list box (lstResults) and stores it in a variable to be passed to another function (to populate fields on the page).

This code was used on an ASP .NET page which is why you see the syntax "id$=" for finding the DOM objects. This syntax is used to ignore the ClientID value the .NET Framework adds to DOM objects at runtime.

  1. $('select[id$=lstResults]').dblclick(function () {
  2. $('select[id$=lstResults] option:selected').each(function () {
  3. var sname = $('select[id$=lstResults] option:selected').text();
  4. var uid = $('select[id$=lstResults] option:selected').val();
  5. ItemSelected(sname, uid);
  6. });
  7. });

Report this snippet  

You need to login to post a comment.