SisiliaPutri
SisiliaPutri

Reputation: 55

How to select another one of radio button?

I made radio buttons and all radio buttons are selected, where I try my code.

How to choose just one radio button in sintaks laravel?

My Picture Page

This is My View Page :

                <div class="form-group">
                    <b>Paket</b>
                    <br/>
                    <fieldset>
                        <input type="checkbox" name="delux" id="delux" value="d"> <label for="">Paket Delux </label>
                        <input type="checkbox" name="paket1" id="p1" value="p1"> <label for="">Paket 1</label>
                        <input type="checkbox" name="paket2" id="p2" value="p2"> <label for="">Paket 2</label>
                    </fieldset>
                </div>
                <div class="form-group">
                    <b>Jenis Pembayaran</b>
                    <br/>
                    <fieldset>
                        <form id="form_radio" name="form_radio">
                        <input type="radio" value="tunai" name="tunai" id="rd1"> <label for="">tunai</label>
                        <br>
                        <input type="radio" value="non" name="nontunai" id="rd2"> <label for="">non tunai</label>
                    </fieldset>
                </div>
                <input type="submit" value="Upload" class="btn btn-primary">
            </form>

And this is My controller :

 public function input()
    {
        $jenis = JenisMkn::select('id_jenis','jenis_makanan')->get();
        return view('upload_gambar',['jenis'=>$jenis]);
    }
    public function proses(Request $request)
    {
       $cek = Gambar::get('checkbox');
       echo $cek;

        $radio = Gambar::get('radio');
        echo $radio;

What the fault in my code?

Any help? Thank you.

Upvotes: 0

Views: 183

Answers (2)

Ivan Bahri
Ivan Bahri

Reputation: 89

Simply give them the same name, cek this code:

<input type="radio" value="tunai" name="transaksi" id="rd1"> <label for="">tunai</label>
<br>
<input type="radio" value="non" name="transaksi" id="rd2"> <label for="">non tunai</label>

You can rename the name input with your name.

Upvotes: 1

Vintage Coders
Vintage Coders

Reputation: 162

If you want only one radio button to get selected then you must specify same value for name property. for example:

<form>
  <input type="radio" name="gender" value="male" checked> Male<br>
  <input type="radio" name="gender" value="female"> Female<br>
  <input type="radio" name="gender" value="other"> Other  
</form> 

Hope it helped.

Upvotes: 0

Related Questions