Hey Matthew,

I attached something that hopefully will help you out!

----- Original Message ----- 
From: "Witango" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 08, 2004 10:56 AM
Subject: Witango-Talk: Dynamically Adding Rows


> I'm trying to write a javascript function for one of my Results pages to
> add input text fields and place the result in another text field.  My
> problem is doing this for a variable number of rows on a given page.
> Here's a simplified version of my implementation that only works in
> Netscape/Mozilla right now.  Any ideas how to get this to work in all
> browsers?  Thanks.
> Matthew.
>
> <script language="JavaScript">
> function add(form, i)
> {
> form.eval("total"+i).value = (form.eval("x"+i).value-0) +
> (form.eval("y"+i).value-0)
> }
> </script>
>
> <form>
> <table>
> <@rows>
> <tr>
> <td><input name="x<@currow>" type="text"
> onChange="add(this.form,<@currow>"></td>
> <td><input name="y<@currow>" type="text"
> onChange="add(this.form,<@currow>"></td>
> <td><input readonly name="total<@currow>" type="text"></td>
> </tr>
> </@rows>
> </table>
> </form>
>
> I also tried the following variation of the function but that doesn't work
> either.
>
> function add(form, i)
> {
> eval("form.total"+i+".value") = (eval("form.x"+i+".value")-0) +
> (eval("form.y"+i+".value")-0)
> }
>
> ________________________________________________________________________
> TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf

________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
<script language="JavaScript">
function add(box,i)
{
  if(box.value=="")
    box.value="0";

  
document.forms['thisform'].elements['total'+i].value=parseFloat(document.forms['thisform'].elements['x'+i].value)+parseFloat(document.forms['thisform'].elements['y'+1].value);
}
</script>

<form name=thisform method=post>
<table>
<@rows>
<tr>
<td><input name="x<@currow>" type="text" 
onChange="add(document.forms['thisform'].elements['x<@currow>'],<@currow>)" 
value="0"></td>
<td><input name="y<@currow>" type="text" 
onChange="add(document.forms['thisform'].elements['y<@currow>'],<@currow>)" 
value="0"></td>
<td><input readonly name="total<@currow>" type="text"></td>
</tr>
</@rows>
</table>
</form>

Reply via email to