简体   繁体   中英

Alert dropdown Label when option is selected using JQuery

I have a table with td's as follows,

In this there are 3 dropdown's where depending on the first dropdown the 2nd and 3rd dropdown's get displayed

Example: when Option 1 or Option 2 is selected from Solutions dropdown, then dropdown with projectslist ID get displayed and when Option 3 is selected then dropdown with projectlist ID get displayed.

    <td>
        <select name="solutions" id="solutions" style="width:210px;">
            <option value="0" label="--- Select Solution ---" selected="selected">--- Select Solution ---</option>
            <option value="1" label="Option 1">Option 1</option>
            <option value="2" label="Option 2">Option 2</option>
            <option value="3" label="Option 3">Option 3</option>
        </select>
    </td>
    <td width="30px;">&nbsp;</td>
    <td><span style="line-height: 1.5;" id="solution_description">Select appropriate monitoring solution.</span>
    </td>
</tr>
<tr height="80px;">
    <td>&nbsp;</td>
</tr>
<tr>
    <td width="50px;"><strong>Project: </strong>
    </td>
    <td id="projectslist">
        <select name="project" id="project" style="width:210px;">
            <option value="0" label="--- Select a Project ---" selected="selected">--- Select a Project ---</option>
            <option value="1" label="Project 1">Project 1</option>
        </select>
    </td>
    <td id="projectlist" style="display:none;">
        <select name="project" id="project" style="width:210px;">
            <option value="0" label="--- Select a Project ---" selected="selected">--- Select a Project ---</option>
            <option value="2" label="Project 2">Project 2</option>
            <option value="3" label="Project 3">Project 3</option>
        </select>
    </td>

Now, I need to get a alert Project Label when ever a Project is selected

ie, when ever Project 1 is selected, I need to alerted that you have selected Project 1 and if Project 2 is selected, then I need to be alerted that you have selected Project 2 and etc...

so can any help me on this using Jquery

Is as simple as listening change event. If you learn the first chapter of "Javascript for dummies" you achieve in 5 minutes.

With jQuery:

  $('#solutions').on('change', function(event) {
       alert("This is the value selected in solutions: " + $(this).val());
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM