|
 |
|
สอบถามเรื่องไฮไลท์สีเมื่อมีการเลือก radio button และ ลบสีเมื่อมีการเลือกข้ออื่น |
|
 |
|
|
 |
 |
|
ใช้ css กำหนดสี
Code (PHP)
<style>
.css_tr_data{ background-color: #dedede; }
.css_tr_data .active{ background-color: #ababab; }
</style>
ใช้ javascript onclick เปลี่ยน class
Code (JavaScript)
<script>
$('input.chk').click(function(){
$(this).parents('tbody').eq(0).find('tr.active').removeClass('active');
$(this).parents('tr').eq(0).addClass('active');
});
</script>
ลองเปลี่่ยน algorithm ในการเขียน ดูครับ จะช่วยให้ ไม่หลงไวยกรณ์
Code (PHP)
<form action ="/" name ="formcheck" id ="formcheck" method ="POST" enctype="multipart/form-data">
<input type="hidden" name="id_data" value="<?=$query_data[0]['id_data']?>">
<input type="hidden" name="id_emp" value="<?=$query_data[0]['id_emp']?>">
<?php
$qusetion = getlist("SELECT * FROM question");
for ($i = 0; $i < sizeof($qusetion); $i++) {
$k = $i + 1;
?>
<table class="table table-borderless" align="center" style="width:250mm;empty-cells: show;" border="1">
<thead>
<tr id="radio" class="qusetion font-weight-bold " style="text-align:left;">
<td colspan='2' class=" text-white" style="background: #07689F;">"
<input type="hidden" name="qusetion[]" value="<?=$qusetion[$i]['qusetion_id']?>" >
<?=$k?> <?=$qusetion[$i]['qusetion_name']?>
</td>
</tr>
</thead>
<tbody>
<?php
$answer = getlist("SELECT * FROM answer where qusetion_id = '" . $qusetion[$i]['qusetion_id'] . "' ");
for ($q = 0; $q < sizeof($answer); $q++) {
$id=$answer[$q]['qusetion_id'];
?>
<tr class="css_tr_data" >
<td align="left" >
<input style="width:35px;height:35px;" type="radio" class="css_data_item" id="answer[<?=$id?>]"
name="answer[<?=$id?>]" value="<?=$id?>]">
<span></span>
</td>
<td><?=$answer[$q]['answer_name']?></td>
</tr>
<?php
}
?>
<tbody>
</table>
<?php
}
?>
<input type="hidden" name="count" value="$q">
<br>
<center>
<input type="submit" name="update" value="บันทึกข้อมูล" class="btn btn-success btn-xl submit_data"
style='font-size:24px;width:250px;height:100px;'>
</center>
<br>
</form>
|
ประวัติการแก้ไข 2022-11-19 14:58:56 2022-11-19 14:59:32
 |
 |
 |
 |
Date :
2022-11-19 14:57:42 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อีกอย่าง ลองเปลี่ยน ไปใช้ foreach แทน for ดูครับ ชีวิตจะง่ายขึ้น
Code (PHP)
foreach( $result as $key=>$array){
//
}
|
 |
 |
 |
 |
Date :
2022-11-19 15:04:30 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|