Which combo box was selected inside a form

0

Hello, Within a form I have 4 combos

<select name="combo1" ><option value="combo1">Combo 1</option> </select>
<select name="combo2" ><option value="combo2">Combo 2</option> </select>
<select name="combo3" ><option value="combo3">Combo 3</option> </select>
<select name="combo4" ><option value="combo4">Combo 4</option> </select>

When a combo is selected, I need to know which of those fates was selected (if it was 1 or 2 or 3 or 4) and get the value of the selected combo.

Thank you.

    
asked by anonymous 31.01.2018 / 17:37

1 answer

2

You can do so:

$('select[name^=combo]').change(function() {
  console.log('select:', this.name)
  console.log('valor selecionado:', this.value)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><selectname="combo1" >
  <option value=""></option> 
  <option value="combo1">Combo 1</option> 
</select>

<select name="combo2" >
  <option value=""></option> 
  <option value="combo2">Combo 2</option> 
</select>

<select name="combo3" >
  <option value=""></option> 
  <option value="combo3">Combo 3</option> 
</select>

<select name="combo4" >
  <option value=""></option> 
  <option value="combo4">Combo 4</option> 
</select>
    
31.01.2018 / 17:44