wont recalculate

Results 1 to 2 of 2

Thread: wont recalculate

  1. #1
    Join Date
    Dec 1969

    Default wont recalculate

    I have a form wherein i want to calculate the value of dynamically generated textfields. i generate the textfields by using a Do loop like this:<BR><BR>a = 1<BR>do while not a &#062; numofitems<BR> &#060;input type="text" name="cost&#060;%=a%&#062;"&#062;<BR>loop<BR><BR>s o for example i numofitems = 5,it would generate 5 rows of textfield with a name of:<BR>cost1<BR>cost2<BR>cost3<BR>cost4<BR>cost5<B R><BR>Now i tried calculating their values using this code:<BR>&#060;script language = "JavaScript"&#062;<BR>function calc2()<BR>{<BR>var b = 0;<BR>var varnum = parseInt(document.form1.numofitems.value); <BR>var varTemp1 = 0; <BR> for(b=0 ; b&#060;=varnum ; b++)<BR> {<BR> varTemp1 = varTemp1 + parseFloat(document.form1["cost" + b].value); <BR> }<BR>}<BR>&#060;/script&#062;<BR><BR>but everytime i run the script, i get this error:<BR>document.form1[...].value is null or not an object<BR><BR>i tried debugging it:<BR>alert(document.form1["cost" + b].value);<BR>so it wont run, that means it becoz of that line.<BR>any ideas?<BR>

  2. #2
    Join Date
    Dec 1969

    Default missing .elements !!

    Try this:<BR> varTemp1 = varTemp1 + parseFloat(document.form1[hl="yellow"].elements[/hl]["cost" + b].value); <BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts