Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Javascript question..Forms..

Status
Not open for further replies.

obtain

MIS
Joined
Dec 4, 2001
Messages
28
Location
US
Hi again,
Thanks to 'twist' this function now executes but I have a problem getting my last line to work. CoutTotale refers to a textbox created within the form and to which I want to send the final calculated value.

function calcul(form)
{
for(var i=0;i<form.nomb.value; i
{ var c13=&quot;text&quot;+i+&quot;13&quot;;
var c17=&quot;text&quot;+i+&quot;17&quot;;
var c21=&quot;text&quot;+i+&quot;21&quot;;
//document.write(form[c13].value);
var r= parseInt(form[c13].value) + parseInt
(form[c17].value) + parseInt(form[c21].value);
//document.write(r);
var cr =&quot;text&quot;+i+&quot;22&quot;;
form[cr].value =r;
}

var CombTotal=0;
for(var d=0;d<form.nomb.value;d++)
{ var cr =&quot;text&quot;+d+&quot;22&quot;;
CombTotal+=parseInt(form[cr].value);
}
//document.write(CombTotal);
form.CoutTotale.value = CombTotal;
//neither does: form[CoutTotale].value=CombTotal;

}



Prob2:Also, when the last line is left out so the function executes, I get a new white screen showing my document.write output..why isn't it writing to the same scrren on which my button and the textboxes are found?

Prob3:In body of document,tried calling function as below replacing the last line in the function calcul(form) with return CombTotal, got an error alertwhen executed:

<input type=&quot;button&quot; value=&quot;Calculer couts&quot; onClick=&quot;this.form.CoutTotale=calcul(this.form)&quot; >
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top