Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
C

chizzy42

@chizzy42
About
Posts
3
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • if statement not working
    C chizzy42

    15100276

    Thanks alot for taking the time to reply in such a detailed way, its much appreciated. its a lot clearer now and the touchscreen project now sums the columns and ive added conditional formatting ...the coding would probably send shivers to your bones but tidying it up and making it more efficient is the next step. Again thanks for taking the time to reply.

    JavaScript html help question

  • if statement not working
    C chizzy42

    hi

    W∴ Balboos

    , thanks for the reply. Ive rethought the condition of the if statement and the following code seems to work. The only issue being if one of the text boxes is left empty then a NaN is given in the result . Just have to make sure the user puts a zero in for that hour just now to prevent that until i think of something else regards

        function sum() {
    
            var txtFirstNo = document.getElementById('Text1').value;
            var txtSecondNo = document.getElementById('Text6').value;
            var txtThirdNo = document.getElementById('Text11').value;
        var txtFourthNo = document.getElementById('Text16').value;
    
    	if(!(document.getElementById('Text1').value).length==0){
                result = parseInt(txtFirstNo);
    	document.getElementById('Tar').value = result;
                }
    
            if(!(document.getElementById('Text6').value).length==0){
    	result = parseInt(txtFirstNo) + parseInt(txtSecondNo);
    	document.getElementById('Tar').value = result;
                }
            
                if(!(document.getElementById('Text11').value).length==0){
    	result = parseInt(txtFirstNo) + parseInt(txtSecondNo) + parseInt(txtThirdNo);
    	document.getElementById('Tar').value = result;
                }
    
                if(!(document.getElementById('Text16').value).length==0){
    	result = parseInt(txtFirstNo) + parseInt(txtSecondNo) + parseInt(txtThirdNo) + parseInt(txtFourthNo);
    	document.getElementById('Tar').value = result;
                }  
        }
    

    ;)

    JavaScript html help question

  • if statement not working
    C chizzy42

    Hi All, Hope all is well well. I have a coding question I cant seem to figure out. I have a form in HTML5 which has columns that I want to sum and show in a totals box. The totals are summed when a button that calls the sum() function when clicked. From the code below I'm just trying to sum two boxes which represent a value for each hour total. My problem is that when I click on the button with only a value in the first box, then i get a NaN in the results box...no matter how many times i click it...but when i enter a value in the second box the sum is completed and the correct total is displayed. Could someone explain please why this only works with 2 values and not just 1....hope this is clear. Thanks to all who try regards

    function sum() {
    var result= 0;
        var txtFirstNo = document.getElementById('Text1').value;
        var txtSecondNo = document.getElementById('Text6').value;
    		
        if (!isNaN(txtFirstNo)){ 
    	result = parseInt(txtFirstNo);
    	document.getElementById('Tar').value = parseInt(result);
            }
            
            if (!isNaN(txtSecondNo)){ 
    	result = parseInt(txtFirstNo) + parseInt(txtSecondNo);
    	document.getElementById('Tar').value = result;
            }
            
           if (!isNaN(result)) {
                document.getElementById('Tar').value = result;
            }
        
        }
    
    JavaScript html help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups