|
![](/images/resource/spacer.gif) |
|
เลือกค่าจาก select box แล้วเอาค่าไอดีที่ได้ไป select ข้อมูลใน java script |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ถ้าไม่อยากใช้ ajax ของ jquery
ก็ลองศึกษา xmlhttprequest ดูครับ
http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2016-06-30 19:42:44 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ลองดูคัฟ
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");
}
}
});
}
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2016-07-01 12:19:41 |
By :
tomguitar |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 02
|