|
|
|
เลือกค่าจาก select box แล้วเอาค่าไอดีที่ได้ไป select ข้อมูลใน java script |
|
|
|
|
|
|
|
ถ้าไม่อยากใช้ ajax ของ jquery
ก็ลองศึกษา xmlhttprequest ดูครับ
http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp
|
|
|
|
|
Date :
2016-06-30 19:42:44 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูคัฟ
Code (PHP)
<select class="form-control" name="carBrand" id="carBrand" required>
<option value="">Choose one</option>
<?php
foreach ($content['brand'] as $row) {
?>
<option
value="<?php echo $row['brandId']; ?>"
<?php if(!empty($contact['brandId'])){ if($contact['brandId']==$row['brandId']){ echo 'selected';}};?>>
<?php echo $row['brandName']; ?>
</option>
<?php
}
?>
</select>
<select class="form-control" name="carModel" id="carModel" required></select>
Code (JavaScript)
$('#carBrand').on('change', function () {
searchModel($(this).val());
});
function searchModel(id) {
$.ajax({
url: "<?php echo root_url('contact/searchModel');?>",
type: "POST",
async: false,
data: {
id: id
},
success: function (result) {
var obj = jQuery.parseJSON(result);
$('#carModel').empty();
for (var i = 0; i < obj.length; i++) {
var selected = '';
if(obj[i]['model']==$('#modelId').val()){
selected = 'selected';
}
console.log(id+' '+obj[i]['modelCode']);
$('<option value="'+obj[i]['model']+'" '+selected+'>'+obj[i]['modelCode']+' '+obj[i]['model']+'</option>').appendTo("#carModel");
}
}
});
}
|
|
|
|
|
Date :
2016-07-01 12:19:41 |
By :
tomguitar |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|