
Originally Posted by
Deathnote
oh this is definitely better...tnx bro...so you can have a function with a capital first letter but not have the same id and name... i thought Add and Add() was different...damn....oh yeah found out that isnan is to check if it is string or not..wow im learning alot from you guyz
but last question i promise...where did val come from? i mean its neither the id nor the name of the check box yet it was used that way...does the control that called the function when you put val on the parameter becomes the value for val? tnx

val = is just an
"argument" (in programming terms) , it holds any
type of value/object, as soon as you call your function. the way you
call your function depends upon who you
declare it.
eg.
Declaration : function add(x,y)
Function call : add(1,2)
Declaration : function display(name,age)
Function call: display("mark", 20)
[/quote]
in my example:
<input type=checkbox Id="idAdd" onClick="fnAdd(this)">
"this" is an
"object" (checkbox) having a method
"Value" (True or False)
in OOP you can call thi commonly
<OBJECT>.<ATTRIBUTES> OR
<OBJECT>.<METHODS>
Methods are also considered as an
attribute, however it performs a certain operation.
you can learn this as soon as you study OOP concept.
try to change the previous lines to this (highlighted as
red) or just copy&paste the code below:
<html>
<head>
<script type="text/javascript">
function fnAdd(objCBox, myString){
if (objCBox.checked) {
sum =parseFloat(calculator.input1.value) + parseFloat(calculator.input2.value);
if (!isNaN(sum)) document.getElementById("output").innerHTML= myString + sum
else document.getElementById("output").innerHTML= "Invalid data."
}
else {
document.getElementById("output").innerHTML= ""
}
}
</script>
</head>
<body>
<form name=calculator>
<input type=checkbox Id="idAdd" onClick="fnAdd(this, 'Total: ')">
<input type=text name=input1>
<input type=text name=input2>
<div id=output> </div>
</form>
</body>
</html>