|
 |
|
สอบถามเรื่องการซ่อน List Option จากการวนลูป php มีตัวอย่างโค๊ดให้ดูครับ |
|
 |
|
|
 |
 |
|
อยากสอบถามการซ่อน List Option ครับ ตอนนี้วนลูปข้อมูลจากฐานข้อมูลได้แล้ว
แต่ต้องการให้มีการซ่อน List ของ Category เมื่อมีการเลือก List Option ของ Type=1
แต่ถ้าเลือก Type2,3,4 ก็แสดง List ของ Category ปกติ
ลักษณะตารางฐานข้อมูลจะเป็นแบบนี้
TypeID | tblType
1 | Type1
2 | Type2
3 | Type3
4 | Type4
CategoryID | tblCategory
1 | Category1
2 | Category2
3 | Category3
4 | Category4
Type
<select name="txtType" id="txtType">
<option value="" selected> == เลือกประเภท == </option>
<?php
$result = mysql_query("
SELECT TypeID, tblType FROM tbl_type");
while($row = mysql_fetch_assoc($result)){
echo '<option value="', $row['TypeID'], '">', $row['tblType'],'</option>';
}
?>
</select>
Category
<select name="txtCategory" id="txtCategory">
<option value="" selected> == เลือกหมวดหมู่ == </option>
<?php
$result = mysql_query("
SELECT CategoryID, tblCategory FROM tbl_category");
while($row = mysql_fetch_assoc($result)){
echo '<option value="', $row['CategoryID'], '">', $row['tblCategory'],'</option>';
}
?>
</select>
Script ตรวจสอบ
$(document).ready(function(){
$('.txtType').change(function(){
var value = $(this).val();
if(value != 1){
$('#txtCategory').hide();
} else {
$('#txtCategory').show();
}
});
ขอบคุณล่วงหน้าทุกคำตอบครับ

Tag : PHP, MySQL, HTML/CSS, JavaScript

|
ประวัติการแก้ไข 2013-04-22 10:56:29
|
 |
 |
 |
 |
Date :
2013-04-22 10:54:54 |
By :
imagineverend |
View :
873 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$(document).ready(function(){
$('.txtType').change(function(){
var value = $(this).val();
if(value == 1){
$('#txtCategory').hide();
} else {
$('#txtCategory').show();
}
});
|
 |
 |
 |
 |
Date :
2013-04-22 11:28:51 |
By :
nid_248 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|