|
|
|
PHP ทำแบบประเมิน แล้วให้คำนวนคะแนนอัตโนมัติครับ |
|
|
|
|
|
|
|
เลือกข้อ 1 - 19 ขึ้น 0
พอเลือกข้อ 20 ขึ้น NaN ครับ
มันไม่คำควณให้อ่ะครับ Help Me !!!
Code (PHP)
<script type='text/javascript'>
function alertData() // คำนวณผล
{
var Rows = document.estimate.hdnRows.value;
for(i=1;i<=Rows;i++)
{
var rdo1 = document.getElementById("score"+i+"_1").checked == true;
var rdo2 = document.getElementById("score"+i+"_2").checked == true;
var rdo3 = document.getElementById("score"+i+"_3").checked == true;
var rdo4 = document.getElementById("score"+i+"_4").checked == true;
var rdo5 = document.getElementById("score"+i+"_5").checked == true;
if(rdo1 == ""){ rdo1 = 0; }
if(rdo2 == ""){ rdo2 = 0; }
if(rdo3 == ""){ rdo3 = 0; }
if(rdo4 == ""){ rdo4 = 0; }
if(rdo5 == ""){ rdo5 = 0; }
document.getElementById("total").value = parseFloat(rdo1) + parseFloat(rdo2) + parseFloat(rdo3) + parseFloat(rdo4) + parseFloat(rdo5);
}
}
</script>
<form name="estimate" action="<?PHP $_SERVER['PHP_SELF']?>">
<table width="100%" cellpadding="0" cellspacing="1" class="tct" border="1">
<tr>
<th rowspan="2">#</th>
<th rowspan="2">เกณฑ์การประเมิน (Description)</th>
<th colspan="5">ระดับคะแนน (Rating Scale)</th>
</tr>
<tr>
<th>5</th>
<th>4</th>
<th>3</th>
<th>2</th>
<th>1</th>
</tr>
<?PHP
$i = 0;
while($show = mysql_fetch_array($result)){
$i = $i + 1;
?>
<tr>
<td width="5%" align="center"><?=$i;?></td>
<td width="70%" style="padding-left: 5px;"><?=$show['evl_detail']?></td>
<td width="5%" align="center"><input type="radio" name="score<?=$i;?>" id="score<?=$i;?>_1" value="5" onClick="alertData();"/></td>
<td width="5%" align="center"><input type="radio" name="score<?=$i;?>" id="score<?=$i;?>_2" value="4" onClick="alertData();"/></td>
<td width="5%" align="center"><input type="radio" name="score<?=$i;?>" id="score<?=$i;?>_3" value="3" onClick="alertData();"/></td>
<td width="5%" align="center"><input type="radio" name="score<?=$i;?>" id="score<?=$i;?>_4" value="2" onClick="alertData();"/></td>
<td width="5%" align="center"><input type="radio" name="score<?=$i;?>" id="score<?=$i;?>_5" value="1" onClick="alertData();"/></td>
</tr> <?PHP } ?>
<tr>
<td width="75%" align="right" colspan="2">รวมคะแนนทั้งหมด (Total) </td>
<td width="25%" align="center" colspan="5"><input type="text" name="total" id="total" value=""/></td>
</tr>
</table><br/>
<input type="hidden" name="hdnRows" value="<?=$i;?>">
<input class="btn" type="submit" name="submit" value="ส่งผลประเมิน"/>
</form>
|
ประวัติการแก้ไข 2014-07-14 14:20:09 2014-07-14 14:21:05
|
|
|
|
Date :
2014-07-14 14:17:34 |
By :
sabaitip |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
พอจะได้แล้วครับ แต่ผมรู้สึกว่า ค่า value ที่อยู่ใน radio button จะไม่ได้นำมาใช้งานเลย
หรือมีวิธีที่ดีกว่านี้มั่งครับ เช่น เลือก radio แล้วคำนวณเลย โดยที่ไม่ต้องเก็บไว้ใน type="hidden" name="total" ก่อน
Code (PHP)
<form name="estimate" action="<?PHP $_SERVER['PHP_SELF']?>" onSubmit="return fncSubmit();">
<table width="100%" cellpadding="0" cellspacing="1" class="tct" border="1">
<tr>
<th rowspan="2">#</th>
<th rowspan="2">เกณฑ์การประเมิน (Description)</th>
<th colspan="5">ระดับคะแนน (Rating Scale)</th>
</tr>
<tr>
<th>5</th>
<th>4</th>
<th>3</th>
<th>2</th>
<th>1</th>
</tr>
<?PHP
$i = 0;
while($show = mysql_fetch_array($result)){
$i = $i + 1;
?>
<tr>
<td width="5%" align="center"><input type="hidden" name="total<?=$i;?>" id="total<?=$i;?>"><?=$i;?></td>
<td width="70%" style="padding-left: 5px;"><?=$show['evl_detail']?></td>
<td width="5%" align="center"><input type="radio" name="score<?=$i;?>" id="score<?=$i;?>_1" value="5" onClick="alertData()"/></td>
<td width="5%" align="center"><input type="radio" name="score<?=$i;?>" id="score<?=$i;?>_2" value="4" onClick="alertData()"/></td>
<td width="5%" align="center"><input type="radio" name="score<?=$i;?>" id="score<?=$i;?>_3" value="3" onClick="alertData()"/></td>
<td width="5%" align="center"><input type="radio" name="score<?=$i;?>" id="score<?=$i;?>_4" value="2" onClick="alertData()"/></td>
<td width="5%" align="center"><input type="radio" name="score<?=$i;?>" id="score<?=$i;?>_5" value="1" onClick="alertData()"/></td>
</tr> <?PHP } ?>
<tr>
<td width="75%" align="right" colspan="2">รวมคะแนนทั้งหมด (Total) </td>
<td width="25%" align="center" colspan="5"><input type="text" name="sum" id="sum" value="0" disabled/></td>
</tr>
</table><br/>
<font color="red">** คุณสามารถประเมินได้เพียงหนึ่งครั้งเท่านั้น **</font><br/><br/>
<input type="hidden" name="hdnRows" value="<?=$i;?>">
<input class="btn" type="submit" name="submit" value="ส่งผลประเมิน"/>
</form>
<script type='text/javascript'>
function alertData() // คำนวณผล
{
var sum = 0;
var Rows = document.estimate.hdnRows.value;
for(var i=1;i<=Rows;i++)
{
if(document.getElementById("score"+i+"_1").checked == true){ document.getElementById("total"+i).value = 5 }
if(document.getElementById("score"+i+"_2").checked == true){ document.getElementById("total"+i).value = 4 }
if(document.getElementById("score"+i+"_3").checked == true){ document.getElementById("total"+i).value = 3 }
if(document.getElementById("score"+i+"_4").checked == true){ document.getElementById("total"+i).value = 2 }
if(document.getElementById("score"+i+"_5").checked == true){ document.getElementById("total"+i).value = 1 }
var total = document.getElementById("total"+i).value;
sum += (total * 1);
}
document.getElementById("sum").value = sum;
}
function fncSubmit() // เช็คค่าว่าง
{
var Rows = document.estimate.hdnRows.value;
for(var i=1;i<=Rows;i++)
{
var s1 = document.getElementById("score"+i+"_1");
var s2 = document.getElementById("score"+i+"_2");
var s3 = document.getElementById("score"+i+"_3");
var s4 = document.getElementById("score"+i+"_4");
var s5 = document.getElementById("score"+i+"_5");
if(s1.checked == false && s2.checked == false && s3.checked == false && s4.checked == false && s5.checked == false)
{
alert('กรุณาให้คะแนนในข้อที่ ' + i);
return false;
}
}
}
</script>
|
ประวัติการแก้ไข 2014-07-15 13:34:31
|
|
|
|
Date :
2014-07-15 13:32:38 |
By :
sabaitip |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าอยากเอาลง database ตามข้อ ควรเขียนแบบไหนครับ
|
|
|
|
|
Date :
2017-10-28 20:17:55 |
By :
chos |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองเอาไปเล่นดู เพื่อจะได้ไอเดีย
Code (PHP)
<?php
$rad='';
if(isset($_POST['rad'])){
$rad = print_r( $_POST['rad'], true);
$r=$_POST['rad'];
}
?><!doctype html>
<html>
<head>
</head>
<body>
<pre><?=$rad?></pre>
<form method="post" >
<table border=1 >
<tr>
<th>Name</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
</tr>
<tr>
<td>Test1</td>
<td><input type="radio" name="rad[0]" value=1 <?=(isset($r)? ($r[0]==1? 'checked':'') : '')?> ></td>
<td><input type="radio" name="rad[0]" value=2 <?=(isset($r)? ($r[0]==2? 'checked':'') : '')?> ></td>
<td><input type="radio" name="rad[0]" value=3 <?=(isset($r)? ($r[0]==3? 'checked':'') : '')?> ></td>
<td><input type="radio" name="rad[0]" value=4 <?=(isset($r)? ($r[0]==4? 'checked':'') : '')?> ></td>
</tr>
<tr>
<td>Test2</td>
<td><input type="radio" name="rad[1]" value=1 <?=(isset($r)? ($r[1]==1? 'checked':'') : '')?> ></td>
<td><input type="radio" name="rad[1]" value=2 <?=(isset($r)? ($r[1]==2? 'checked':'') : '')?> ></td>
<td><input type="radio" name="rad[1]" value=3 <?=(isset($r)? ($r[1]==3? 'checked':'') : '')?> ></td>
<td><input type="radio" name="rad[1]" value=4 <?=(isset($r)? ($r[1]==4? 'checked':'') : '')?> ></td>
</tr>
<tr>
<td>Test3</td>
<td><input type="radio" name="rad[2]" value=1 <?=(isset($r)? ($r[2]==1? 'checked':'') : '')?> ></td>
<td><input type="radio" name="rad[2]" value=2 <?=(isset($r)? ($r[2]==2? 'checked':'') : '')?> ></td>
<td><input type="radio" name="rad[2]" value=3 <?=(isset($r)? ($r[2]==3? 'checked':'') : '')?> ></td>
<td><input type="radio" name="rad[2]" value=4 <?=(isset($r)? ($r[2]==4? 'checked':'') : '')?> ></td>
</tr>
</table>
<button>Submit</button>
</form>
</body>
</html>
|
ประวัติการแก้ไข 2017-10-29 11:53:22
|
|
|
|
Date :
2017-10-29 11:51:53 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีตัวอย่างที่แก้ไขสมบูรณ์แล้วมั้ยครับ
|
|
|
|
|
Date :
2018-04-11 08:38:23 |
By :
ชัยวัฒน์ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form name="eval" action="">
<table width="70%" cellpadding="0" cellspacing="1" class="tct" border="1">
<tr>
<th rowspan="2">#</th>
<th rowspan="2">เกณฑ์การประเมิน (Description)</th>
<th colspan="5">ระดับคะแนน (Rating Scale)</th>
</tr>
<tr>
<th>5</th>
<th>4</th>
<th>3</th>
<th>2</th>
<th>1</th>
</tr>
<tr>
<td width="5%" align="center">1</td>
<td width="70%" style="padding-left: 5px;">title 1</td>
<td width="5%" align="center"><input type="radio" id="score_1" name="score_1" value="5"/></td>
<td width="5%" align="center"><input type="radio" id="score_1" name="score_1" value="4"/></td>
<td width="5%" align="center"><input type="radio" id="score_1" name="score_1" value="3"/></td>
<td width="5%" align="center"><input type="radio" id="score_1" name="score_1" value="2"/></td>
<td width="5%" align="center"><input type="radio" id="score_1" name="score_1" value="1"/></td>
</tr>
<tr>
<td width="5%" align="center">2</td>
<td width="70%" style="padding-left: 5px;">title 2</td>
<td width="5%" align="center"><input type="radio" id="score_2" name="score_2" value="5"/></td>
<td width="5%" align="center"><input type="radio" id="score_2" name="score_2" value="4"/></td>
<td width="5%" align="center"><input type="radio" id="score_2" name="score_2" value="3"/></td>
<td width="5%" align="center"><input type="radio" id="score_2" name="score_2" value="2"/></td>
<td width="5%" align="center"><input type="radio" id="score_2" name="score_2" value="1"/></td>
</tr>
<tr>
<td width="5%" align="center">3</td>
<td width="70%" style="padding-left: 5px;">title 3</td>
<td width="5%" align="center"><input type="radio" id="score_3" name="score_3" value="5"/></td>
<td width="5%" align="center"><input type="radio" id="score_3" name="score_3" value="4"/></td>
<td width="5%" align="center"><input type="radio" id="score_3" name="score_3" value="3"/></td>
<td width="5%" align="center"><input type="radio" id="score_3" name="score_3" value="2"/></td>
<td width="5%" align="center"><input type="radio" id="score_3" name="score_3" value="1"/></td>
</tr>
<tr>
<td width="75%" align="right" colspan="2">รวมคะแนนทั้งหมด (Total) </td>
<td width="5%" align="center" colspan="5" id="sum_socre">0</td>
</tr>
</table>
</form>
<script type='text/javascript'>
var sum = 0;
var add_value = [];
$('input[type=radio]').change(function(){
// add value
add_value[this.name] = this.value;
// reset sum
sum = 0;
for(var key in add_value){
sum = parseInt(sum) + parseInt(add_value[key])
}
$('#sum_socre').html(sum);
console.log(sum);
});
</script>
*คงประมาณนี้ลองเอาไปปรับแต่งดู
|
|
|
|
|
Date :
2018-04-11 14:02:42 |
By :
ไม่ประสงค์ออกนาม |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีตัวอย่างที่ทำเสร็จแล้วมั้ยครับ มือใหม่หัดทำ อยากได้ Code มาลองเล่นครับ
|
|
|
|
|
Date :
2018-05-10 08:44:17 |
By :
ชัยวัฒน์ ศรีบุรินทร์ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีตัวที่เสร็จแล้วมั้ยครับ ขอหน่อยได้มั้ยครับ
|
|
|
|
|
Date :
2018-10-08 10:33:04 |
By :
Unknow |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตรงนี้เป็นแหล่งตอบปัญหา และ การเรียนรู้ ต้องช่วยตัวเองบ้างนะครับ
แล้วติดปัญหายังไงเอาโค๊ดมาถาม
และจริงๆ โค๊ดตัวอย่างที่อยากจะเอาไปศึกษามีตั้งเยอะแยะ ไม่จำเป็นต้องเป็นโค๊ดแบบนี้หรอกครับ
ถ้าอยากได้แบบนี้และสำเร็จเลย ช่วยจ้างกันได้ไหม 55555
|
|
|
|
|
Date :
2018-10-08 11:55:24 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2020-03-19 14:58:15 |
By :
thip |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>SU_INDEX</title>
<link rel="stylesheet" href="dist/css/bootstrap.css">
<link rel="icon" href="assets/img/ms.png" type="image/x-icon">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
.navbar {
width: 0 auto;
margin: 0 auto;
font-family: 'Noto Sans Lao';
}
.navbar1 {
font-family: 'Noto Sans Lao';
text-align: center;
}
.container-fluid{
font-family: 'Noto Sans Lao';
}
.container{
text-align: center;
}
.wrapper{
width: 650px;
margin: 0 auto;
font-family: 'Noto Sans Lao';
font-size: 15px;
line-height: 1.42857143;
color: #a94442;
background-color: #fff;
}
.page-header h2{
margin-top: 0;
}
table tr td:last-child a{
margin-right: 15px;
}
.b{
background-color:;
}
.c{
background-color: #cb2301ba;
}
.a1{
background-color: #da8b7bf2;
}
.nav{
color:dark;
}
input[type='radio'] {
-webkit-appearance: none;
width: 20px;
height: 20px;
border: 1px solid darkgray;
border-radius: 50%;
outline: none;
box-shadow: 0 0 5px 0px gray inset;
}
input[type='radio']:hover {
box-shadow: 0 0 5px 0px orange inset;
}
input[type='radio']:before {
content: '';
display: block;
width: 60%;
height: 60%;
margin: 20% auto;
border-radius: 50%;
}
input[type='radio']:checked:before {
background: red;
}
</style>
</head>
<body>
<?php include('includes/header.php') ?>
<?php include('includes/navbar.php') ?>
<?php include('config.php')?>
<div class="container-fluid border border-defult"><br>
<h4><center>ແບບປະເມີນການສອນຂອງອາຈານພາຍໃນຄະນະວິສະວະກຳສາດ</center></h4>
<div class="row">
<div>
</div>
<div class="a col-sm col-md-2"><br>
<!-- Grid column -->
<div class="col-md-12 ">
</div>
<!-- Grid column -->
</div>
<div class="b col-ms col-md-8 ">
<br>
<form id="save" name="save" method="post" action="create_eva_save.php">
<!--<input type="text" id="ttt" name="ttt2" value="55" />-->
<table id="question" border="1">
<thead>
<tr>
<th width="5%" height="40" bgcolor='#9ea3a8' ><center>ລຳດັບ</center></th>
<th width="1300" bgcolor='#ccced1'><center>ເນື້ອໃນປະເມີນອາຈານສອນ</center></th>
<th width="100" bgcolor='#ccced1'><center>5 ດີຫຼາຍ</center></th>
<th width="100" bgcolor='#ccced1'><center>4 ດີ</center></th>
<th width="100" bgcolor='#ccced1'><center>3 ປານກາງ</center></th>
<th width="100" bgcolor='#ccced1'><center>2 ໜ້ອຍ</center></th>
<th width="120" bgcolor='#ccced1'><center>1 ໜ້ອຍສຸດ</center></th>
</tr>
</thead>
<?php
$form_id=1;
$no=0;
//$sql="select * from tb_question_list order by qtn_id desc";
$sql="select * from tb_question_list
INNER JOIN tb_question_answer ON tb_question_list.qtn_id = tb_question_answer.ans_qtn_ref
WHERE qf_id = $form_id ";
$result = $link ->query($sql);
while($rs = $result ->fetch_object()){
$no++;
$id=$rs->qtn_id;
$check = array('','','','','','');
$check[$rs->ans_qtn_value] = "checked=checked";
?>
<tbody>
<tr>
<td width="5%" height="30" align="center"><?=$no;?></td>
<td><?=$rs->qtn_title;?></td>
<td width="8%" height="30" align="center"><input type="radio" name="choice<?=$id;?>" value="5" <?=$check[5];?>/></td>
<td width="8%" height="30" align="center"><input type="radio" name="choice<?=$id;?>" value="4" <?=$check[4];?>/></td>
<td width="8%" height="30" align="center"><input type="radio" name="choice<?=$id;?>" value="3" <?=$check[3];?>/></td>
<td width="8%" height="30" align="center"><input type="radio" name="choice<?=$id;?>" value="2" <?=$check[2];?>/></td>
<td width="8%" height="30" align="center"><input type="radio" name="choice<?=$id;?>" value="1" <?=$check[1];?>/></td>
</tr>
</tbody>
<?php } ?>
</table><br>
<br>
<button type="submit" name="save" class="btn btn-outline-success"> ສົ່ງແບບປະເມີນ </button>
</div>
<div class="a col-sm col-md-2 "><br>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>
|
|
|
|
|
Date :
2020-03-19 14:59:40 |
By :
thip |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|