SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Running total script not working every time - AJAX function interfering?

    Hello
    I'm setting up a timesheet entry page, which will automatically calculate running totals using javascript. The user of my page gets to the relevant timesheet by choosing the week from a drop-down box. I then use an AJAX technique to populate a DIV with the inputs for the relevant form - that way if the timesheet already exists it can be amended, or if it doesn't exist it can be created.

    However, the running total function is only working every other time a timesheet is selected from the drop down box. There's probably a simple explanation for this, but I'm stuck...

    Here's my javascript for the running totals - the function is called "onchange" in each input. There are two rows and a column for each day, plus totals. (The form validation isn't done properly yet, obviously).

    Code:
    function valueChange(value)
    	{
       var ValidChars = "0123456789.";
       var IsNumber=true;
       var Char;
    
     
       for (i = 0; i < value.length && IsNumber == true; i++) 
          { 
          Char = value.charAt(i); 
          if (ValidChars.indexOf(Char) == -1) 
             {
             IsNumber = false;
    		 alert('Enter numbers only');
    		 return false;
             }
          }
    
    
    		var projtotal = 0;
    		projtotal = Number(document.getElementById('projday1').value) + Number(document.getElementById('projday2').value) + Number(document.getElementById('projday3').value) + Number(document.getElementById('projday4').value) + Number(document.getElementById('projday5').value) + Number(document.getElementById('projday6').value) + Number(document.getElementById('projday7').value);
    		document.getElementById("projtotal").value=projtotal;
    
    		var commtotal = 0;
    		commtotal = Number(document.getElementById('commday1').value) + Number(document.getElementById('commday2').value) + Number(document.getElementById('commday3').value) + Number(document.getElementById('commday4').value) + Number(document.getElementById('commday5').value) + Number(document.getElementById('commday6').value) + Number(document.getElementById('commday7').value);
    		document.getElementById("commtotal").value=commtotal;
    
    		var grandtotal = Number(document.getElementById('commtotal').value) + Number(document.getElementById('projtotal').value);
    		document.getElementById("totalhours").value=grandtotal;
    
    		var mondaytotal = 0;
    		mondaytotal = Number(document.getElementById('projday1').value) + Number(document.getElementById('commday1').value);
    		document.getElementById("monsub").value=mondaytotal;
    
    		var tuesdaytotal = 0;
    		tuesdaytotal = Number(document.getElementById('projday2').value) + Number(document.getElementById('commday2').value);
    		document.getElementById("tuesub").value=tuesdaytotal;
    
    		var wednesdaytotal = 0;
    		wednesdaytotal = Number(document.getElementById('projday3').value) + Number(document.getElementById('commday3').value);
    		document.getElementById("wedsub").value=wednesdaytotal;
    
    		var thursdaytotal = 0;
    		thursdaytotal = Number(document.getElementById('projday4').value) + Number(document.getElementById('commday4').value);
    		document.getElementById("thusub").value=thursdaytotal;
    
    		var fridaytotal = 0;
    		fridaytotal = Number(document.getElementById('projday5').value) + Number(document.getElementById('commday5').value);
    		document.getElementById("frisub").value=fridaytotal;
    
    		var saturdaytotal = 0;
    		saturdaytotal = Number(document.getElementById('projday6').value) + Number(document.getElementById('commday6').value);
    		document.getElementById("satsub").value=saturdaytotal;
    
    		var sundaytotal = 0;
    		sundaytotal = Number(document.getElementById('projday7').value) + Number(document.getElementById('commday7').value);
    		document.getElementById("sunsub").value=sundaytotal;
    
    	}
    All help gratefully received. Apologies if I haven't made the problem clear enough.

  2. #2
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just tested in IE6 and script doesn't actually work at all there. Any help gratefully received.


Bookmarks

Posting Permissions

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