[Nfb-web] java script, still cant subtract

Graham Mehl blind at trailstone.com
Sat Jan 26 01:03:33 UTC 2013


Hi Bryan,
It depends on what the purpose of the alert statement you want to add.
If you want to have an alert pop up every time the user clicks a checkbox,
but 
only provides the total team value once, then put your alert statement
directly after the line
            }//end if salary check
But before this line
        }//end unnamed function
This way, if the user does exceed the max salary, it will re-adjust the
total value before providing how much the user spent.
As I mentioned in other correspondences, I would have some other functions
and clean my solution up, this works.
Hopefully it is what you were looking for?
--
Graham
blind at trailstone.com


-----Original Message-----
From: Bryan Schulz [mailto:b.schulz at sbcglobal.net] 
Sent: Friday, January 25, 2013 4:37 PM
To: NFB Webmaster's List
Subject: Re: [Nfb-web] java script, still cant subtract

hi Graham,

nice, seems close.
can you think where to put:
alert ("you have spent: "+teamValue)
i put it just above:
}//end second for loop
and it fires 30 times without returning to the form because it is inside the
for loop and there are 30 checkboxes in this sample.
any farther down and it won't fire until the total exceeds a limit.
thanks.
Bryan Schulz

----- Original Message -----
From: "Graham Mehl" <blind at trailstone.com>
To: "'NFB Webmaster's List'" <nfb-web at nfbnet.org>
Sent: Friday, January 25, 2013 4:33 AM
Subject: Re: [Nfb-web] java script, still cant subtract


> 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
>
>
> _______________________________________________
> Nfb-web mailing list
> Nfb-web at nfbnet.org
> http://nfbnet.org/mailman/listinfo/nfb-web_nfbnet.org
> To unsubscribe, change your list options or get your account info for 
> Nfb-web:
>
http://nfbnet.org/mailman/options/nfb-web_nfbnet.org/b.schulz%40sbcglobal.ne
t 


_______________________________________________
Nfb-web mailing list
Nfb-web at nfbnet.org
http://nfbnet.org/mailman/listinfo/nfb-web_nfbnet.org
To unsubscribe, change your list options or get your account info for
Nfb-web:
http://nfbnet.org/mailman/options/nfb-web_nfbnet.org/blind%40trailstone.com





More information about the NFB-Web mailing list