Hi friends,
I have a form with textboxes that gets passed to a Javascript function inthe head of my document when a button is clicked.
Problem: Textboxes are automatically named in a for loop in tthe form so to know which one to call I must also have a for loop in my Javascript function.
So I have:
<SCRIPT LANGUAGE="JavaScript">
function calcul(form)
{
//calculates total for 3 boxes in a row of a table
//and inserts the total into a fourth box in the row.
//i represents number of rows there are in the table.
//Table initially constructed in the form that is
//passed in so all variables for the textboxes are
//known.
for(var i=0;i<form.nombre.value; i++)
{
var c13="text"+i+"13";//name of a textbox,so get
// text013
var c17="text"+i+"17";
var c21="text"+i+"21";
document.write(form.c13.value);//prob:error here
//system cant doesn't replace c13 with text013
//so that the value of that textbox is received..
//i.e. I get "form.c13.value=undefined",when I need
//form.text013.value= some number, so rest below
//is not executed, same prob below
var r = form.c13.value + form.c17.value+
form.c21.value;
document.write(r);
var cr ="text"+i+"22";
form.cr.value =r;
}
var CombTotal=0;
for(var d=0;d<form.nomb.value;d++)//set total for
// each row
{ var cr ="text"+d+"22";
CombTotal+=form.cr.value;
}
form.CoutTotale.value =CombTotal;
}
</SCRIPT>
I have a form with textboxes that gets passed to a Javascript function inthe head of my document when a button is clicked.
Problem: Textboxes are automatically named in a for loop in tthe form so to know which one to call I must also have a for loop in my Javascript function.
So I have:
<SCRIPT LANGUAGE="JavaScript">
function calcul(form)
{
//calculates total for 3 boxes in a row of a table
//and inserts the total into a fourth box in the row.
//i represents number of rows there are in the table.
//Table initially constructed in the form that is
//passed in so all variables for the textboxes are
//known.
for(var i=0;i<form.nombre.value; i++)
{
var c13="text"+i+"13";//name of a textbox,so get
// text013
var c17="text"+i+"17";
var c21="text"+i+"21";
document.write(form.c13.value);//prob:error here
//system cant doesn't replace c13 with text013
//so that the value of that textbox is received..
//i.e. I get "form.c13.value=undefined",when I need
//form.text013.value= some number, so rest below
//is not executed, same prob below
var r = form.c13.value + form.c17.value+
form.c21.value;
document.write(r);
var cr ="text"+i+"22";
form.cr.value =r;
}
var CombTotal=0;
for(var d=0;d<form.nomb.value;d++)//set total for
// each row
{ var cr ="text"+d+"22";
CombTotal+=form.cr.value;
}
form.CoutTotale.value =CombTotal;
}
</SCRIPT>