Zhafari Irsyad
Zhafari Irsyad

Reputation: 83

How to set and get cookie for multiple radiobutton Laravel Javascript

I am having trouble saving the quiz answer to the recurring radiobutton cookie.

How do I save the value of my radio button that has been clicked into Cookies?

This is my blade for the radio button

<form action="" method="post">
    <small class="text-muted">Pertanyaan ke 1 dari {{ count($quiz) }}</small>
    <br>
    @foreach($quiz as $q)
    @php
        $quiz_questions = App\QuizQuestion::where('quiz_id',$q->id)->orderBy('priority', 'asc')->get();
    @endphp
    @endforeach

    @foreach($quiz_questions as $key=>$qq)

        <div style="margin:1% 0%; padding:2%; background-color:#EEEEEE;">
        <p><strong>{{$key+1}}) {{$qq->question}}</strong></p>
        @php
        $quiz_answers= App\QuizAnswer::where('quiz_question_id', $qq->id)->get();
        @endphp

        @foreach($quiz_answers as $qa)
            <div class="radio-inline">
            <label for="">
            <input required type="radio"  name="ans[{{$qq->id}}]" id="ans[{{$qq->id}}]" value="{{$qa->id}}">&nbsp&nbsp{{$qa->answer}}
            </div>
            <br>
        @endforeach
        </div>
    @endforeach
    <button class="btn btn-default pull-right">Lanjut</button>
</form>

and it looks like this

enter image description here

Is it possible if I want to save my radiobuttons values into Cookie?

If it's possible, I don't know how, maybe you can help me to solve it

I use Laravel version 7 and javascript

Upvotes: 0

Views: 71

Answers (0)

Related Questions