Can help me check this code

2007-07-27 9:00 pm
function calculate() {
var n1=parseInt(firstnum.value);
var n2=parseInt(secondnum.value);
result.value=n1+n2;
}
function reset() {
firstnum.value="";
secondnum.value="";
result.value="";
}
function check(field) {
if (isNaN=(field.value)){
alert("Invalid please try again!");
return false;
}
else
return true;
}

This code when key in 1 and 2 num clickadd the result no appear??

回答 (2)

2007-07-27 9:07 pm
✔ 最佳答案
function calculate() {
var n1=parseInt(firstnum.value);
var n2=parseInt(secondnum.value);
result.value=n1+n2;
}
function reset() {
firstnum.value="";
secondnum.value=&;quot;"; <---&;quot 換成 &quot
result.value="";
}
function check(field) {
if (isNaN=(field.value)){
alert("Invalid please try again!");
return false;
}
else
return true;
}

2007-07-27 13:10:26 補充:
打唔到,係咁將我D字 變左 "
2007-07-30 7:06 pm
I believe that the problem is the script cannot detect what "firstnum","secondnum", "result" is.

First, you should add id="firstnum" into the tag where you wish to be firstnum

Then, in the script, change firstnum into:

document.getElementById("firstnum")

The problem should be solved.


收錄日期: 2021-04-13 00:53:44
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070727000051KK01940

檢視 Wayback Machine 備份