0
votes

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
1
You could use the change event which jquery provides on t the drop down box get the value of the selected option, and switch on that to do your respective actions - krishwader
This is what I wand to do. But this is the code I have to work on, and in this case, being new to jquery, I could use some help to use it properly - Kapn0batai
I posted an answer. Maybe itll help you - krishwader

1 Answers

1
votes

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