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.
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 */.
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:
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.
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.
You need to use a change
event :
Template.myTemplate.events({
"change #orderStatus": function(event, template){
var selectValue = template.$("#orderStatus").val();
console.log(selectValue);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With