Finally - checkbox check limit, but... a few issues
Last Post 01-19-2010 02:55 PM by Chad Nash. 2 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
Richard BaileyUser is Offline
going with the flow
going with the flow
Posts:66
Avatar

--
01-15-2010 12:07 PM

    I finally, after weeks of trying, go at least an alert to pop up when too many check boxes are checked.

    Issue 1:

    I have a checkbox list shortnamed 'measures'

    and another hidden field name max_count

    my function accepts the the checkbox list field ID and a max_count to set the limit.

    CountCheckedBoxesInList($(measures_FieldID),$(max_count))

    It works fine if I manually enter the max_count value in the Client Side event of the question as well as the initial javascript

    CountCheckedBoxesInList($(measures_FieldID),6)

     

    However, using it with the $(max_count) from the hidden field it doesn't ever fire.   I am completely stumped... more stumped than I was getting it to work in the first place

     

    Issue 2

    Now, this isn't really an issue, but something I haven't been able to get working.  I'd like the function to Un-check (checked = false) the last checked box - but can't seem to get that working.

    I had assumed since I am passing the function $(measures_FieldID) that I could use that directly, but it never ever seems to work.

     

    The function:

    This is the function, it is a hack of one of the built-in functions and I haven't cleaned it up any.  I'm not a java developer, so feel free to recommend any improvements to the code below - I literally just by dumb luck got it working... It is in the javascript file.

    function CountCheckedBoxesInList(CheckBoxList,themax) {
    var thelimit = Number(themax);
    if(thelimit > 0) {
    var objChkBoxLst = document.getElementById(CheckBoxList);
    if(objChkBoxLst) {
    var objChkBoxes = objChkBoxLst.getElementsByTagName('input');
    var objChkLabels = objChkBoxLst.getElementsByTagName('label');
    var i; var numSum = 0;           
    for(i=0;i if(objChkBoxes.checked) {                   
    numSum += 1;
    }
    }
    }
    if(numSum <= thelimit)
    {
    return true;
    }
    if(numSum > thelimit)
    {
    alert("You may only select a maximum of " + thelimit + " measures");
    }
    }
    }

     

     

    Richard BaileyUser is Offline
    going with the flow
    going with the flow
    Posts:66
    Avatar

    --
    01-19-2010 05:22 AM
    bump... still having a hard time with the passing of the variables
    Chad NashUser is Offline
    Posts:5260
    Avatar

    --
    01-19-2010 02:55 PM
    Hi Richard... sorry, David review the forums more however he is out this week on vacation.

    For issue #1: if you enable debug mode what is the JavaScript it shows that is generated? Make sure it looks something like 'document.getelementbyid something...' and not $(max_count). Oh... one more thing... there is a built in function call for performance to only process $(Tokens) if they use client side events. This is for performance on large forms but can be troublesome if you don't have any actual client side event for max_count. To get around this simply enter something in the client side event such as 'var nothing;'. This will then recognize that it needs to replace $(Max_count) instead of skipping it.

    For issue #2: Each client side event and functionality is different and I am not directly familiar with updating specific checkbox's however... I would imagine you could add alerts into that function to make sure you have the right object first and then trying a few options to actually run the checkbox. I did find this URL:

    http://www.developertutorials.com/t...page1.html

    Not sure if this works for checkbox's or only check box lists but it does show how to set the value to false about 1/2 way down the page. Maybe in the area where you are 'returning true' you could also add code to set that value = false right there?


    Also, just a notice that our standard support doesn't include actually writing client side events or implementations. If you are on a deadline and need a more direct approach (or things such as go to meetings, us to code or modify code to support the implementation) we do offer these through Premium Support at http://www.datasprings.com/Premium-Support. It sounds like you are rounding 3rd base and you might not need this but just keep this in mind in the future.

    One last tip... I would for sure install Firebug for Firefox and enable the console app there. This can making debugging JavaScript much easier. I would also suggest using the debug often and seeing what JavaScript is actually getting rendered.

    Thanks, and good luck! I am sure other users would find this function useful and we greatly appreciate your contributions in the forums!


    Chad


    ---
  • film izle
  • 720 izle
  • film
  • sinema izle
  • film makinesi
  • T�rk�e dublaj film
  • film izle
  • film izle
  • baglan film izle
  • sinema izle
  • 1080 film izle
  • film mercegi