How to use jQuery to load the values in the form fields when the corresponding radio button is selected?
have a form that has some radio buttons. Each radio button corresponds to a registration type of a conference. For that I have this code:
- @foreach($registrationType as $rtype)
- <div class="form-check">
- <input class="form-check-input" type="radio" name="radiobutton" id="{{$rtype->id}}" value="option1">
- <label class="form-check-label" for="exampleRadios1">
- {{$rtype->name}}
- </label>
- </div>
- @endforeach
Below the radio buttons, the form has some fields and I want to show in this fields the information of each selected registration type. This part I'm in doubt how to do it.
First I load the values for each registration type and store them in a array:
- $(function() {
- var registrationTypes = {!! $registrationTypeJson !!}
- alert(registrationTypes) // returns "[object Object]""
- });
But then how to use jquery to load the values in the form fields when the corresponding radio button is selected?
Full form:
- <form method="post" class="clearfix">
- <div class="form-row">
- <div class="form-group col col-lg-6">
- <label for="registration_types">Registration Types</label>
- @foreach($registrationType as $rtype)
- <div class="form-check">
- <input class="form-check-input" type="radio" name="radiobutton" id="{{$rtype->id}}" value="option1">
- <label class="form-check-label" for="exampleRadios1">
- {{$rtype->name}}
- </label>
- </div>
- @endforeach
- </div>
- </div>
- <div class="form-group">
- <label for="registration_type_name">Registration Type Name</label>
- <input type="text" required class="form-control" value="{{ $rtype->nome }}" name="registration_type_name" id="registration_type_name">
- </div>
- <div class="form-group">
- <label for="registration_type_capacity">Capacity</label>
- <input type="number" min="1"
- required class="form-control" value="{{ $rtype->capacity }}"
- name="registration_type_capacity" id="registration_type_capacity">
- </div>
- <!-- more registration type info fields -->
- </div>
- <input type="submit" class="btn btn-primary" value="Update registration type"/>
- </form>