how to deactivate fetch value database to select box in laravel 4 - html

Iam trying to edit student details.
iam fetch values from database. blood group fetch from database to display select box. and also display other blood groups in same select box.
select class="form-control" name="studbldgrp" id="studbldgrp">
option value="{{$student->studbldgrp}}">{{$student->studbldgrp}}</option>
option value="O+ve">O+ve</option>
option value="O-ve">O-ve</option>
<option value="A+ve">A+ve</option>
<option value="A-ve">A-ve</option>
<option value="B+ve">B+ve</option>
<option value="B-ve">B-ve</option>
<option value="AB+ve">AB+ve</option>
<option value="AB-ve">AB-ve</option>
<option value="Other">Other</option>
</select>
my problem is if im fetch value is A+ ,and display in select box. but it also in option value field.
i no need to again this value(A+)A +ve in select option field.
how to disable this field???

Create an array of your groups. Than iterate over it and don't print value matches $student->studbldgrp.
Array in php:
$groups = array(
'O+ve',
'O-ve',
'A+ve',
'A-ve',
'B+ve',
'B-ve',
'AB+ve',
'AB-ve',
'Other'
);
Blade template:
<select class="form-control" name="studbldgrp" id="studbldgrp">
<option value="{{$student->studbldgrp}}">{{$student->studbldgrp}}</option>
#foreach ($groups as $group)
#if ($group != $struden->studbldgrp)
<option value="{{ $group }}">{{ $group }}</option>
#endif
#endforeach
</select>

Related

How to getting selected option value with another table in laravel?

<select class="custom-select rounded-0" id="exampleSelectRounded0" name="kode_poli">
#foreach ($polikliniks as $poliklinik)
<option value="{{$poliklinik->id}}">{{$poliklinik->kode_poli}} | {{$poliklinik->nama_poli}}</option>
#endforeach
</select>
My select option value will return a first id of poliklinik table
How to set select option 'selected' with another value in poliklinik table with my selected value when i insert before?
You will need to write an option with the selected id as the value and selected name in between the option tag
<select class="custom-select rounded-0" id="exampleSelectRounded0" name="kode_poli">
<option value="{{$selected->id}}">{{$selected->kode_poli}}</option>
#foreach ($polikliniks as $poliklinik)
<option value="{{$poliklinik->id}}">{{$poliklinik->kode_poli}}</option>
#endforeach
</select>
Note: substitute the selected with the model you used in saving it

Laravel/Blade: pre-selected dropdown option

I am using a foreach loop to generate a drop down list via bensampo's ENUMS library, but I need to be able to preselect one of them as I have an edit view and I need it to load the option that is in my database.
My select in my edit view:
<select name="type" id="type" class="form-control">
#foreach ($MailMessageTypes as $value =>$label)
<option value="{{$value}}">{{$label}}</option>
#endforeach
</select>
My function edit in my MailMessageController:
return view('MailMessage.edit', [
'MailMessage' => $MailMessage],
["MailMessageTypes" => MailMessageType::toSelectArray()
]);
I tried to use the enum library's getValues() and getKeys() in the controller but that generates (duplicates) for me, since the foreach keeps generating all options. I am using the select2 plugin
Added: I'm using the select2 plugin for the list.
On your Edit page, you are passing the existing mail message as $MailMessage. I am assuming your database has its value as id, so it can be accessed as $MailMessage->id. While you are looping through and displaying each option, you need to check if that option's value equals the id of the message you are editing. If it matches, you set the selected attribute on the <option>:
<select name="type" id="type" class="form-control">
#foreach ($MailMessageTypes as $value => $label)
<option value="{{$value}}" {{($MailMessage->id == $value) ? 'selected' : ''}}>
{{$label}}
</option>
#endforeach
</select>
In your HTML your <select> would end up looking something like:
<select name="type" id="type" class="form-control">
<option value="1">COM01</option>
<option value="2" selected>COM02</option>
<option value="3">COM03</option>
// ... the rest of the options
</select>

Prevent select box from changing

I'm working on an angular js 2 project and I need to create a dropdown (kinda like a link) wherein if you select an option it will trigger an onchange event and redirect the user. Currently I have this:
<select id = "dashboard" onchange="goToPage()" class="form-control">
<option value="" selected disabled>{{ 'Create' | translate }}</option>
<option value="Applicant" >{{ "dashboard.applicant" | translate}}</option>
<option value="Reports">{{ "dashboard.report" | translate}}</option>
</select>
In the select box I want the 'Create' option to always be selected even if the applicant selects Applicant or Reports. How can I do this behavior?
You can't cast onchange if user can't change selected value at all, but you can place inside your function this line document.getElementById("dashboard").selectedIndex = 0; which will select first option again:
function goToPage(){
document.getElementById("dashboard").selectedIndex = 0;
}
<select id = "dashboard" onchange="goToPage()" class="form-control">
<option value="" selected disabled>{{ 'Create' | translate }}</option>
<option value="Applicant" >{{ "dashboard.applicant" | translate}}</option>
<option value="Reports" >{{ "dashboard.report" | translate}}</option>
</select>

default select box by a passed parameter to django template?

I'm passing a dictionary to a django template and trying to set a default value for a select box. This template is an 'edit product' template for a previous 'add product' template, thus the user selected one of the following options from a select box when he added a new product and what I am trying to do now is in the 'edit product' template so he can change it while the default will be as the one he selected at first.
Is there a way to do something like this:
<td><select name="gender_limit" deafault="{{django_context.gender}}">
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Both">Both</option>
</select>
</td>
Rather than:
<td><select name="gender_limit" >
<option value="Male" selected >Male</option>
<option value="Female">Female</option>
<option value="Both">Both</option>
</select>
</td>
I have tried to look a solution for this but haven't found. Any help is appreciated. Thanks
I found a solution to my problem, here is an example (a different one from the question example):
<select name="units">
<option ng-selected="'{{ med.units }}' == 'mg' " value="mg">mg</option>
<option ng-selected="'{{ med.units }}' == 'gr' " value="gr">gr</option>
<option ng-selected="'{{ med.units }}' == 'mcg' " value="mcg">mcg</option>
<option ng-selected="'{{ med.units }}' == 'ng' " value="ng">ng</option>
</select>
Or even as so:
<select name="units" ng-model="'{{ med.units }}'">
<option value="mg">mg</option>
<option value="gr">gr</option>
<option value="mcg">mcg</option>
<option value="ng">ng</option>
</select>
med.units is django context passed from a view.

How to set the default select input value based on database value [duplicate]

This question already has answers here:
ColdFusion how to set form input values from the results of a cfquery?
(2 answers)
Closed 7 years ago.
Is it possible to set a select inputs default value based on a value returned by a database query? Where below getFormData.color_it = 'RAL7035TXT'
<cfquery name="getFormData" datasource="RC">
SELECT *
FROM RFQ_Data
WHERE form_ID = <cfqueryparam value="#ARGUMENTS.rfqID#">
</cfquery>
<select name="color_it">
<option value="RAL9005TXT">RAL9005TXT </option>
<option value="RAL7035TXT">RAL7035TXT </option>
<option value="other">Other </option>
</select>
The result I am looking for would change the select so that the option with the value RAL7035TXT would be on top so it is the default. (see below)
<select name="color_it">
<option value="RAL7035TXT">RAL7035TXT </option>
<option value="RAL9005TXT">RAL9005TXT </option>
<option value="other">Other </option>
</select>
Would this have to be done with with a lot of if statements?
Looks like my question was answered in one of my other questions: ColdFusion how to set form input values from the results of a cfquery?
You can set default selected value:
<select name="color_it">
<option value="RAL7035TXT"selected="selected" >RAL7035TXT </option>
<option value="RAL9005TXT">RAL9005TXT </option>
<option value="other">Other </option>
</select>
If you want to use value in the select that is received by the database you can just save the query in a php variable and use this value in the tag like this:
<option value="<?php echo $value; ?>"><?php echo $value; ?></option>