Mihir Naik
Mihir Naik

Reputation: 3

Get Dropdown value dynamically row wise

<select class="form-control demo-select2-placeholder" name="company" id="company">
<option value="">{{ ('Select Your Company') }}</option>
  @foreach (\App\Company::all() as $company)
     <option value="{{ $company->id }}">
          {{ $company->company_name }}
     </option>
  @endforeach
</select>

/* function written */

<script>
$('#company').change(function(){
   var companyID = $(this).val();
   window.alert(companyID);
 });
</script>

How do I derive value from the dropdown for every row, Now the drop-down works only for the first row

Upvotes: 0

Views: 74

Answers (1)

Dylan KAS
Dylan KAS

Reputation: 5683

Only one select has the id #company so you could try to target each select[name="company"] instead.

So change your jQuery selector to:

<script>
$('select[name="company"]').change(function(){
   var companyID = $(this).val();
   window.alert(companyID);
});
</script>

Upvotes: 2

Related Questions