ผมขอถามเกี่ยวกับ JavaScript หน่อยครับ พอดีผมกำลังทำเกี่ยวกับเว็บ
นี่ code ครับ
<td><input type="text" name="score" size="3" id="score_" onKeyUp="calculate()" onKeyPress="CheckNum()" maxlength="3" ></td>
<td><input type="text" name="score2" size="3" id="score2_"onKeyUp="calculate()" onKeyPress="CheckNum()"maxlength="3" class="form-control " ></td>
<td><input type="text" name="score3" size="3" id="score3_" onKeyUp="calculate()" onKeyPress="CheckNum()"maxlength="3" class="form-control "></td>
<td><input type="text" name="scorefull" id="scorefull" maxlength="3" size="3" class="form-control "readonly /></td>
<input name="scoure%" type="hidden" id="scoure4" readonly maxlength="3" class="form-control " />
<td><input class="form-control "readonly id="scoregrad" maxlength="3" type="text" name="scoregrad" size="3" disabled ></td>
<script type='text/javascript'>
function checkNumber(elm){
if(elm.value>50){
alert('can not input over 50');
elm.value='';
}
}
</script>
<script language="javascript">
function CheckNum(){
if (event.keyCode < 48 || event.keyCode > 57){
event.returnValue = false;
}
}
</script>
<script language="javascript">
function calculate()
{
var scorefull_ = 0;
var scoregrad = "-";
var scoure4_ = "-";
var score = parseInt(document.getElementById('score_').value);
var score2 = parseInt(document.getElementById('score2_' ).value);
var score3 = parseInt(document.getElementById('score3_').value);
if ( isNaN(score) )
{
score = 0;
}
if ( isNaN(score2) )
{
score2 = 0;
}
if ( isNaN(score3) )
{
score3 = 0;
}
scorefull_=score+score2+score3;
if (scorefull_) {
scoure4_ = (scorefull_ /100)*80;
document.getElementById('scoure4').value = scoure4_;
}
if (scorefull_>=80) {
document.getElementById('scoregrad').value = "A";
}
else
if (scorefull_>=75) {
document.getElementById('scoregrad').value = "B+";
} else
if (scorefull_>=70) {
document.getElementById('scoregrad').value = "B";
} else
if (scorefull_>=65) {
document.getElementById('scoregrad').value = "C+";
}
else
if (scorefull_>=60) {
document.getElementById('scoregrad').value = "C";
}
else
if (scorefull_>=55) {
document.getElementById('scoregrad').value = "D+";
}else
if (scorefull_>=50) {
document.getElementById('scoregrad').value = "D";
}
document.getElementById('scorefull').value = scorefull_;
if(scorefull_>100) {
alert('can not input over 100');
if (score > 0 ) {
score5 = scorefull_ - 100;
score6 = score- score5;
document.getElementById('score_').value =score6;
}
else if ( score2 > 0) {
score5 = scorefull_ - 100;
score7 = score2- score5;
document.getElementById('score2_').value =score7;
}
else if ( score3 > 0) {
score5 = scorefull_ - 100;
score8 = score3- score5;
document.getElementById('score3_').value =score8;
}
document.getElementById('scorefull').value =100;
}
}
</script>
<td><input type="text" name="score" size="3" id="score_" onKeyUp="calculate()" onKeyPress="CheckNum()" maxlength="3" ></td>
<td><input type="text" name="score2" size="3" id="score2_"onKeyUp="calculate()" onKeyPress="CheckNum()"maxlength="3" class="form-control " ></td>
<td><input type="text" name="score3" size="3" id="score3_" onKeyUp="calculate()" onKeyPress="CheckNum()"maxlength="3" class="form-control "></td>
<td><input type="text" name="scorefull" id="scorefull" maxlength="3" size="3" class="form-control "readonly /></td>
<input name="scoure%" type="hidden" id="scoure4" readonly maxlength="3" class="form-control " />
<td><input class="form-control "readonly id="scoregrad" maxlength="3" type="text" name="scoregrad" size="3" disabled ></td>
<script type='text/javascript'>
function checkNumber(elm){
if(elm.value>50){
alert('can not input over 50');
elm.value='';
}
}
</script>
<script language="javascript">
function CheckNum(){
if (event.keyCode < 48 || event.keyCode > 57){
event.returnValue = false;
}
}
</script>
<script language="javascript">
function calculate()
{
var scorefull_ = 0;
var scoregrad = "-";
var scoure4_ = "-";
var score = parseInt(document.getElementById('score_').value);
var score2 = parseInt(document.getElementById('score2_' ).value);
var score3 = parseInt(document.getElementById('score3_').value);
if ( isNaN(score) )
{
score = 0;
}
if ( isNaN(score2) )
{
score2 = 0;
}
if ( isNaN(score3) )
{
score3 = 0;
}
scorefull_=score+score2+score3;
if (scorefull_) {
scoure4_ = (scorefull_ /100)*80;
document.getElementById('scoure4').value = scoure4_;
}
if (scorefull_>=80) {
document.getElementById('scoregrad').value = "A";
}
else
if (scorefull_>=75) {
document.getElementById('scoregrad').value = "B+";
} else
if (scorefull_>=70) {
document.getElementById('scoregrad').value = "B";
} else
if (scorefull_>=65) {
document.getElementById('scoregrad').value = "C+";
}
else
if (scorefull_>=60) {
document.getElementById('scoregrad').value = "C";
}
else
if (scorefull_>=55) {
document.getElementById('scoregrad').value = "D+";
}else
if (scorefull_>=50) {
document.getElementById('scoregrad').value = "D";
}
document.getElementById('scorefull').value = scorefull_;
if(scorefull_>100) {
alert('can not input over 100');
if (score > 0 ) {
score5 = scorefull_ - 100;
score6 = score- score5;
document.getElementById('score_').value =score6;
}
else if ( score2 > 0) {
score5 = scorefull_ - 100;
score7 = score2- score5;
document.getElementById('score2_').value =score7;
}
else if ( score3 > 0) {
score5 = scorefull_ - 100;
score8 = score3- score5;
document.getElementById('score3_').value =score8;
}
document.getElementById('scorefull').value =100;
}
}
</script>
ถามว่า ?