Ad
Laravel Put Html Select Dropdown "selected" At Two Data
I've check the data based on user details to auto selected the list from dropdown like below
<option {{ $user->grade == "10" ? 'selected' : '' }} value="10">10</option>
<option {{ $user->grade == "10 (A)" ? 'selected' : '' }} value="10 (A)">10 (A)</option>
please notice that space
is there in 10 (A)
But in the form (page) both of them are putting selected
(the user grade is 10
)
how to avoid this things. Data type of grade is string
Thanks in advance
Ad
Answer
It seems $user->grade
in not a string
variable. You can cast your variable to string
and then compare it
<option {{ (string)$user->grade == "10" ? 'selected' : '' }} value="10">10</option>
<option {{ (string)$user->grade == "10 (A)" ? 'selected' : '' }} value="10 (A)">10 (A)</option>
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad