I know I can set selected attribute for a select tag with old put filed:
<select name="country" id="state" onChange="loadlist(this.value);" >
<option value="usa" {{ (old('state') == 'usa') ? 'selected' : '' }}>USA</option>
<option value="grm" {{ (old('state') == 'grm') ? 'selected' : '' }}>Germany</option>
<option value="eng" {{ (old('state') == 'eng') ? 'selected' : '' }}>England</option>
</select>
But in that form, I have another select tag that use from a Jquery file for load options:
<select name="state" id="state" class="form-control arrow-black">
<option value="">Select country</option>
</select>
the Jquery codes:
function loadlist(country){
with(document.getElementById('state'))
{
options.length = 0;
if(country == ''){
options[0] = new Option('Select country' , '');
}
if (country == 'usa') {
options[0] = new Option('Select' , '');
options[1] = new Option('NewYork' , 'NewYork');
options[2] = new Option('Florida' , 'Florida');
options[3] = new Option('California' , 'California');
}
if (country == 'grm') {
options[0] = new Option('Select' , '');
options[1] = new Option('Bayern' , 'Bayern');
options[2] = new Option('Hamburg' , 'Hamburg');
options[3] = new Option('Berlin' , 'Berlin');
}
if (country == 'eng') {
options[0] = new Option('Select' , '');
options[1] = new Option('Buckingham' , 'Buckingham');
options[2] = new Option('Cambridge' , 'Cambridge');
options[3] = new Option('London' , 'London');
}
}
}
how can I set {{ (old('state') == 'The state name') ? 'selected' : '' }}
{{ (old('state') == 'The state name') ? 'selected' : '' }}
for the 2nd select tag?
只需在页面加载时重新加载第二个选择:
$( document ).ready(loadlist($("select[name=country] " ). Val() ) );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.