pordonez
8 months ago

Get the value of select box with same class

Posted 8 months ago by pordonez

PHP:

@foreach($test as $t)

<button id="btn">Choose</button>

<select name="select_test">
<option value="0">0</option>
<option value="1">1</option>
</select>
@endforeach

jQuery:

$('#btn').on('click', function() {
    var select = $('select[name="select_test"]').val();
    alert(select);
});

Issue: I have 5 buttons and 5 select drop down. but when i click the 2nd, 3rd, 4th and 5th button it will display the 1st select value. its always the 1st select value.

How can i get the value of the select base on the button i clicked?.

Please sign in or create an account to participate in this conversation.