jQuery: Double Click to Add


/ Published in: jQuery
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.