Kapn0batai
Kapn0batai

Reputation: 215

JQuery drop-down list selection

I'm kind of new with JQuery, so this is what I'm trying to do: here I'm creating a drop-down menu when clicking on the icon (called 'otherActions').

If the user selects the first I want it do do something (like reset password). If the second one is selected I want it to do something else.

How can I do this using JQuery? I don't know where the methods should be placed. Thank you so much for the help!

var otherActions = $('<div class="icon" style="...." title="..."></div>');
$(otherActions).click(function()
{
    var menuDiv = $('#otherActions');
    if (menuDiv.length == 0)
    {
        menuDiv = $('<div id="otherActions" class="myObject" style="..."></div>');
        $('body').append(menuDiv);
    }
    otherActions = new myObject(menuDiv);  
    otherActions.addItem('Action 1', 0);      //myObject methods 
    otherActions.addItem('Action 2', 1);
    otherActions.popupXY(x, y);            //myObject method that creates the drop-down list
});
result.append(otherActions); // this is just one of the icons I have to set up

Upvotes: 0

Views: 345

Answers (1)

krishwader
krishwader

Reputation: 11371

You could use jquery's change(). This will be triggered when you change a value in the drop down menu. Usage would be something like this :

$("select").change(
 function () {
  var val=this.value;
  switch (val)
  {
    case "reset" :
     //do action for reset
     break;
    case "someother" :
     //do something else
     break;
   }
)

Note You'll have to put this code after you append the drop down into your html. Your drop down must exist in the DOM for this event to get attached to the dropdown. For note info on this, see docs

Upvotes: 1

Related Questions