Hi, guys. How are you?
I am strugling calculating values of text box.
I generated input text boxes inside of the loop.
They are named price and quant.
Then I wanted to do like price * quant = cost when I click calcualte button, you know.
and print on the page.
But some reason, it just say: NaN, NaN, Nan......
Hmm.....Here is my code:
code:
<html>
<head>
<title>Shop Form</title>
<script type="text/javascript">
function calculate(){
var price = parseInt(document.theForm.price.value);
var quant = parseInt(document.theForm.quant.value);
var total = 0;
for(i=1; i<=10; i++){
total=price*quant;
document.write(total);
}
}
</script>
</head>
<body>
<form name="theForm">
<script type="text/javascript">
for(i=1; i<=10; i++){
document.write("<input type='text' name='price' value='0'>" );
document.write("<input type='text' name='quant' value='0'>" );
document.write("<br >");
}
</script>
<input type="button" onClick="calculate()" value="Get total">
</form>
</body>
</html>
I haven't done JavaScript for a while.....
Easy to forget...........
Help.
Hiroki Kozai