-2

I need to create a function to do something if a specific selectable list is chosen and show an alert.

<select name="location" data-c="location" class="filter valid cc_cursor" aria-invalid="false">
    <option value="" selected="selected">-</option>
    <option value="2">Newyork Clinic</option>
    <option value="1">Center Hospital</option>
</select>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • 1
    You have asked this same question about 3 times with various different accounts. Firstly, please read the reason for the closures each time. In addition, repeatedly asking the same question with multiple accounts is likely to get you banned. – Rory McCrossan Jan 04 '21 at 15:05
  • Onkar Singh solved my problem.if you give more effort for solve problems and help people instead of close question, may it will be better for humanity – Mary Jquery Jan 04 '21 at 15:17
  • Look at the reason the question was closed. There is a link to a pre-existing question which already details the code you need to use. – Rory McCrossan Jan 04 '21 at 15:18
  • understand the same thing, similar issues are addressed into another post, but sometimes another side non-technical person and can't able to understand, and they want to answer over their own question, so I have comments and try to help – Onkar Jan 04 '21 at 15:22

1 Answers1

0

Use change event to detect the value of select tag

jQuery(function($){
  $(document).on('change', 'select[name="location"]', function(){
    if( $(this).val() != '' ){
      alert('option selected...');
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="location" data-c="location" class="filter valid cc_cursor" aria-invalid="false">
<option value="" selected="selected">-</option>
<option value="2">
Newyork Clinic</option>
<option value="1">Center Hospital</option>
</select>
Onkar
  • 2,409
  • 2
  • 11
  • 14