attempting to do custom calculations for an Adobe fillable form, but getting NaN
I'm trying to do some basic math calculations to get the total of my form. The problem I'm running into is when a checkbox is not being checked, code is not working. It works when all three are checked though. The checkboxes are mon, tue and wed.
There is probably something wrong with my javascript syntax...
var conf = this.getField("conference");
var conf_check = false;
if(conf.value == 3 || conf.value == 4){
conf_check = true;
}
switch (conf.val开发者_运维知识库ue) {
case 1: result = 625; break;
case 2: result = 850; break;
case 3: result = 220; break;
case 4: result = 275; break;
default: result = 0;
}
if(conf_check == true){
var total_multiplier = 0;
if(this.getField("mon").value != "NaN"){
total_multiplier = total_multiplier + this.getField("mon").value;
}
if(this.getField("tue").value !="NaN"){
total_multiplier = total_multiplier + this.getField("tue").value;
}
if(this.getField("wed").value != "NaN"){
total_multiplier = total_multiplier + this.getField("wed").value;
}
var total = total_multiplier * result;
} else {
total = result;
}
event.value = total;
Basically if there is one NaN checkbox it ruins the calculations.
He is a check function in javascript.
<html>
<head>
<script language=javascript>
function validate(chk){
if (chk.checked == 1)
alert("Thank You");
else
alert("You didn't check it! Let me check it for you.")
chk.checked = 1;
}
</script>
</head>
<body>
<form>
<input type=checkbox name=chk1>Please Check Me
<p><input type=button value="check" onclick="return validate(chk1);">
</form>
</body>
</html>
http://www.devx.com/tips/Tip/13204
Your tests will always pass, even when the value is NaN. First, I'm not so sure isNaN("NaN") == true.
Second: NaN != NaN. You must use isNaN() instead of ==.
Not A Number is not equal to Not A Number.
精彩评论