Which combo was selected within a form

Asked

Viewed 43 times

0

Hello, Inside 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 among these four, which one was selected (if it was 1 or 2 or 3 or 4) and take the value of the selected combo.

Thank you.

1 answer

2


You can do that:

$('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>
<select name="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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.