在我的html格式中,我有9個下拉值,如果用戶操作是編輯,那麼它會從數據庫中獲取值並返回jsonencode format.as下面,我如何使下拉值使用jsonencode數據使用Javascript選擇
JSON數據
[{"ed_gender":"Male","ed_blood_group":"A-","ed_marital_status":"Single","ed_branch_id":"11","ed_desig_id":"1","ed_job_type":"Permanent","ed_pay_mode":"Cheque"}]
HTML
<select name="ed_gender" class="form-control">
<option value="">Select</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
<select name="ed_marital_status" class="form-control">
<option value="">Select</option>
<option value="Single">Single</option>
<option value="Married">Married</option>
</select>
我嘗試了幾行代碼使用PHP其實際工作,但我想使用JavaScript。
PHP
<select name="ed_marital_status" class="form-control">
<option value="">Select</option>
<option <?php if($ed_marital_status=="Single") echo 'selected="selected"'; ?> value="Single">Single</option>
<option <?php if($ed_marital_status=="Married") echo 'selected="selected"'; ?> value="Married">Married</option>
</select>
所以在這裏老實話,我要提取JSON值並下拉值在頁面加載有「選擇」。
編輯:
JSON數據
[{"ed_branch_id":"11","ed_desig_id":"1"}]
HTML
<select name="ed_job_location" class="form-control">
<option value="">Select</option>
<?php
foreach($get_branches as $branches){
$branches_id = $branches->b_id;
$branches_name = $branches->b_name;
$branches_code = $branches->b_code;
echo "<option value='$branches_id||$branches_name||$branches_code'>$branches_name</option>";
}?>
</select>
<select name="ed_desig_id" class="form-control">
<option value="">Select</option>
<?php
foreach($get_designation as $designations){
$designations_id = $designations->d_id;
$designations_name = $designations->d_designation;
$designations_code = $designations->d_code;
echo "<option value='$designations_id||$designations_code'>$designations_name</option>";
}?>
</select>
從上面的JSON
在這裏,我只得到分支ID和DESIG ID,但她我對||有價值在選擇選項中的符號,所以我需要找到特定的ID並在下拉菜單中顯示它。
嗨,你的意思是你想使用JSON數據插入到HTML選擇,你 –
是完全相同,但不能插入,我需要選擇下拉@威利 – Khalid