Home > Blockchain >  I am trying to add a checked attribute before submitting form and to have the clicked radio sticky u
I am trying to add a checked attribute before submitting form and to have the clicked radio sticky u

Time:10-27

I am using laravel 8. I managed to get a radio button sticky using the blade template but I can't figure out how to use the checked attribute before submitting and then have the clicked radio button come back checked without it reverting to the default checked.

here's my radio button:

<label for="no" class="col form-check-label">No</label>
<input type="radio" checked name="visualCheck" value="no" id="no" class="col p-0 m-0" style="display:inline-block;vertical-align:middle;"  @if(old('visualCheck')=='no') checked @endif />

<label for="yes" class="col form-check-label">Yes</label>
<input type="radio" name="visualCheck" value="yes" id="yes" class="col" style="display:inline-block;vertical-align:middle;" @if(old('visualCheck')=='yes') checked @endif />                         

CodePudding user response:

You might wanna modify and use this code. But, this is how it can be done.

<input type="radio" name="visualCheck" id="no" class="col p-0 m-0" style="display:inline-block;vertical-align:middle;" value="no" {{ old('visualCheck') == "yes" ? 'checked='.'"'.'checked'.'"' : '' }} />

You can see this link. Here

  • Related