javascript - Assign button value within a loop - Laravel blade

@foreach($sections as $section)
<div class="main_content_body">
<div class="main_content_bodyhead">
<h4>{{ $section->section_name }}</h4>
{{ $section->id }}
<button id="Knowthesection" value="{{ $section->id }}" type="button" class="button1" data-toggle="modal" data-target="#updatesectionmodal" onclick=getsectionid()>
Update section name
</button>
</div>
<div class="main_content_bodycontent">
<td>content 1</td><br><br>
<td>content 2</td>
</div>
</div>
@endforeach
<script>
function getsectionid(){
var sec_id = document.getElementById('Knowthesection').value;
alert(sec_id);
}
</script>
I try to assign the value for the button within a loop. But when I alert the value out. It always shows the first looping value. The section->id above the button is display perfectly, but the section->id within the button is not. Do anyone know the reason? How can i solve it. Thank you.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: using $this when not in object context
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.