Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have One Selectbox which consist of 4 values. I want to call function for specific value. On button where we can call only on function onClick. So what I want is like if value is 1 selected then call function 1 on button click and so on.

What I have tried:

Please suggest me some code.

<pre><td>
  <div class="dropdown">
   <select id="myDropdown" class="dropbtn" data-native-menu="true"> 
                        <option selected="selected">Search▼</option>
                        <option value="Alert" id="Alert">Alert</option>
                        <option value="Incident Report">IR</option>
                        <option value="Site">Site</option>
                        <option value="Device">Devices</option>                     
                    </select></div>
  </td>


this is the dropdown
<pre><td> 
<button type="submit" onclick="SearchContext()" id="searchbutton" style="height:50px; width:150px" class="searchbtn">Search Now</button>
</td>

and this is the button
Posted
Updated 31-Jul-17 19:36pm

1 solution

In SearchContext, take the selected value and use a switch to decide which function to call:
JavaScript
function SearchContext() {
    var selectedValue = document.getElementById("myDropdown").value;
    switch (selectedValue) {
        case "Alert":
            alertButtonClicked();
            break;
        case "Incident Report":
            irButtonClicked();
            break;
        case "Site":
            siteButtonClicked();
            break;
        case "Device":
            deviceButtonClicked();
            break;
    }
}
Replace the ...ButtonClicked names with your actual function names.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900