Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onClick event for dropdown list meteor javascript

is there a way I can add a click event to a dropdown menu in Meteor? I know how to do it for buttons, but I couldn't find documentation for dropdown menus. My dropdown menu is:

<td>
    <select id="orderStatus">
        <option value="Submitted">Submitted</option>
        <option value="Sent">Sent</option>
        <option value="Complete">Complete</option>
    </select>
</td>

I want an click event that alerts with the value of the option that i selected. For example, I select "Sent" in the dropdown menu, I want an alert "Sent".

Thank you.

like image 705
Trung Tran Avatar asked Jun 08 '15 00:06

Trung Tran


People also ask

How do I create a dropdown button using onclick?

Using onclick to create a dropdown button: // Get the button, and when the user clicks on it, execute myFunction. document.getElementById("myBtn").onclick = function() {myFunction()}; /* myFunction toggles between adding and removing the show class, which is used to hide and show the dropdown content */.

When does the onclick event occur in JavaScript?

More "Try it Yourself" examples below. The onclick event occurs when the user clicks on an element. Note: The addEventListener () method is not supported in Internet Explorer 8 and earlier versions. Another example on how to change the color of a <p> element by clicking on it:

How to create a dropdown menu using clicky-menus?

The “clicky-menus” is a lightweight JavaScript plugin that helps you to create a dropdown menu onclick event. The menu comes with a one-level dropdown menu that can be opened with a click, tap, or keyboard enter / space key (when it is focused). The plugin converts each parent item (dropdown link) to the button element to expand dropdowns.

How to create a dropdown list in HTML using JavaScript?

The <select> tab is used with <option> tab to create the simple dropdown list in HTML. After that JavaScript helps to perform operation with this list. Other than this, you can use the container tab <div> to create the dropdown list.


1 Answers

You need to use a change event :

Template.myTemplate.events({
  "change #orderStatus": function(event, template){
    var selectValue = template.$("#orderStatus").val();
    console.log(selectValue);
  }
});
like image 54
saimeunt Avatar answered Sep 20 '22 14:09

saimeunt