[Nfb-web] java script, still cant subtract

Graham Mehl blind at trailstone.com
Fri Jan 25 10:33:59 UTC 2013


Hi Bryan,
Not sure if you figured this out yet, but I have a working solution.
I am running late for work, but I wanted to get the answer out ASAP.
There are a number of issues with the javascript.
It took me forever to figure out the root problem.
Your second for loop is looping only over one line of code.
There is a line above that for loop that has "onclick=function() {"
The I thought the second for loop had a close bracket, but it is this
unnamed function that the bracket goes to.
The last major error is in how you get the salary value. You are only
replacing one comma and not all of them with a blank.
If you need more explaination, please let me know.

function linkMsg() {
alert ("linked to external java script");
}//end linkMsg function

function countCB(checkgroup, limit){
    var checkgroup=checkgroup
    var limit=limit
    var salaryCapStr="8000000"
    var salaryCap=parseInt(salaryCapStr)

    for (var i=0; i<checkgroup.length; i++){
        checkgroup[i].onclick=function(){
        var checkedcount=0
        var teamValue=0

        for (var i=0; i<checkgroup.length; i++){
            checkedcount+=(checkgroup[i].checked)? 1 : 0
            checkboxValue=this.value
            checkboxValue=checkboxValue.replace(/,/g, '')
            checkboxValue=checkboxValue.split("$")
            driverValue=parseInt(checkboxValue[1])
            teamValue+=(checkgroup[i].checked)? driverValue : 0

          }//end second for loop
            if (checkedcount>limit){
              alert("You can only select a maximum of "+limit+" checkboxes")
              this.checked=false
            }//end if checkbox count

           if (teamValue>salaryCap){
               alert("You cannot spend more than $8,000,000")
               teamValue=parseInt(teamValue) - parseInt(driverValue)
               this.checked=false
            }//end if salary check
        }//end unnamed function
    }// end first for loop
}//end countCB function

--
Graham
blind at trailstone.com

-----Original Message-----
From: Bryan Schulz [mailto:b.schulz at sbcglobal.net] 
Sent: Tuesday, January 22, 2013 5:59 PM
To: nfb-web at nfbnet.org
Cc: b.schulz at sbcglobal.net
Subject: [Nfb-web] java script, still cant subtract

hi,

the html test file and java script source file are attached, remove .txt
from the code file.
looking to give a reward for solution with explanation of what i can't see:

1st click on any checkbox checks the box and adds the driver total to the
team total.
2nd click on the same checkbox/driver should subtract the value from the
total but it doesn't.

thanks.
Bryan Schulz





More information about the NFB-Web mailing list