Assign id attribute to form checkbox element

Published 9 months ago by JokersMild85

I'm trying to assign an id attribute to checkbox elements of my form. What I am writing is causing the checkboxes to be checked by default and not providing an id attribute. Can anyone provide some insight?

Here is the code:

@foreach($exercise_type->exercises as $exercise)

    {!! Form::label('exercise_name', $exercise->exercise_name) !!}
    {!! Form::checkbox( 'exercise[]', "{$exercise->id},{$exercise->exercise_type_id},{$exercise->exercise_name}"), ['id' => "{$exercise->exercise_name}"] !!}
    </br>

@endforeach
jlrdw
jlrdw
9 months ago (245,820 XP)
JokersMild85

Can you please clarify how the example you provided sets the id property of the checkbox element?

robrogers3

let's just write some html shall we:

<input type="checkbox" name="exercise[]" value="{{$exercise->id}}">
<input type="checkbox" name="exercise[]" value="{{$exercise->exercise_type_id}}">
<input type="checkbox" name="exercise[]" value="{{$exercise->name}}">

awesome now we don't have to debug.

but now what about an id, for the elements. well you can give one their own UNIQUE id, There can be only one!

Or you can give them a class (for some reason)

Or just get them via javascript.

let checkBoxes = document.querySelectorAll('input[name="exercise[]"]') //done

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