Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 18th, 2011, 11:11 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default Adding values issue

Hi JS people

Why can I not do this:

Code:
document.getElementById("bt" + j).value = Number(document.getElementById("bt" + j).value) + Number(document.getElementById("bt" + j + i).value);
Its simply adding the value of one text box to another. The form field names are dynamic usinf ASP that why I have said:

"bt" + i and "bt" + j

The i and j are variables which are counters be incremented inside a for loop

TYIA
__________________
Wind is your friend
Matt
 
Old May 19th, 2011, 03:33 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well I'd use parseInt or parseFloat instead of Number but what are you getting as a result? You could try parentheses around the i + j (and use the += operator shortcut:
Code:
document.getElementById("bt" + j).value
 += Number(document.getElementById("bt" + (j + i)).value);
If that doesn't work I suggest breaking the operation down into smaller steps to see exactly which part is failing.
__________________
Joe
http://joe.fawcett.name/
 
Old May 19th, 2011, 07:37 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Hi joefawcett thank you for your time...

I initially thoght there may be a syntax issue which was why I was getting the 'objject required' script error which is occuring on thr one single line of code I posted. It appears however thats not the case after I stripped it appart. That line of code is inside a couple of For loops:

Code:
function updateTotalsBT() {
   var i=0;
   var j=1;
   updateForm.btST.value = 0;
   for (i=0;i<4;i++) {
     document.getElementById("btT" + i).value = 0;
   }
   for (j=1;j<=6;j++) {
     document.getElementById("bt" + j).value = 0;
     document.getElementById("ST" + j).value = Number(document.getElementById("nt" + j).value) + Number(document.getElementById("lt" + j).value);
     for (i=0;i<4;i++) {
       document.getElementById("bt" + j).value = Number(document.getElementById("bt" + j).value) + Number(document.getElementById("bt" + j + i).value); //Horiz Totals
    document.getElementById("btT" + i).value = Number(document.getElementById("btT" + i).value) + Number(document.getElementById("bt" + j + i).value); //Vert Totals
    updateForm.btST.value = Number(updateForm.btST.value) + Number(document.getElementById("bt" + j + i).value);
    document.getElementById("ST" + j).value = Number(document.getElementById("ST" + j).value) + Number(document.getElementById("bt" + j + i).value);
    if (Number(document.getElementById("bt" + j + i).value)>0) {
      document.getElementById("bt" + j + i).style.background = '#FCF3C4';
    }
     }
   }
      updateForm.ST.value = Number(updateForm.btST.value) + Number(updateForm.ntST.value) + Number(updateForm.ltST.value);   
 }
I do beleive my issue is a form filed name which the function is dynamicly creating does not exist on the page. The page is a timesheet. the:

for (j=1;j<=6;j++)

part of the code goes over the Monday - Sunday input boxes and simplt totals the sums onFocus/onBlur.

I ahve a html version of the page that the ASP code generates here:

http://www.framegroup.com.au/portals.../Timesheet.htm

my issue is when the focus goes on Mon 16 May input field to enter a value its throwing the object required on line 21 (which is the line i originally posted)

Am a bit stuck

TYIA
__________________
Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Distinct Values 1.0 musman0047 XSLT 2 February 25th, 2009 04:48 PM
adding values between datasets Ashubhatt BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 0 June 19th, 2008 04:37 AM
Adding Values NeilS21 Beginning VB 6 1 February 6th, 2004 10:45 AM
Adding time values scott Access 8 January 11th, 2004 05:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.