Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have four check box list on my aspx page.
The scenario is that each check box list have check boxes with different-different value.
I want that when any user click on those check boxes then sum of value of all selected checkboxes if crosses 1 then it shows a message like that it exceeds 1

i am using the following javascript function
C#
<script type="text/javascript" language="javascript">
        //-------------------function hardcode to perform on checklist box--------
        var total = 0;
        var histvalue = 0;
        var valueOfbx = 0;
        var currvalue = 0;
        function MutExChkList(chk) {
            if (chk.checked) {
                valueOfbx = 0;
                var chklst = chk.parentNode.parentNode.parentNode;
                var chkbx = chklst.getElementsByTagName("input");
                for (var i = 0; i < chkbx.length; i++) {
                    if ((chkbx[i].checked == true) && (chkbx[i].value != chk.value)) {
                        valueOfbx = Number(chkbx[i].value);
                        histvalue = -1;
                        chkbx[i].checked = false;
                    }
                    else if ((chkbx[i].checked == true) && (chkbx[i].value == chk.value)) {
                        currvalue = Number(chkbx[i].value);
                    }
                }
                total = total + currvalue;
                if (histvalue == -1) {
                    total = total - valueOfbx;
                    histvalue = 0;
                }
                if (total > 1) {
                    total = total - Number(chk.value);
                    chk.checked = false;
                    alert("exceeds");
                }
                else
                    chkbx[i].checked = false;
            }
            else {
                total = total - Number(chk.value);
            }
        }

    </script>


it works perfectly on my system but as i tried to work this on other systems then it does not value of checkboxes
Please help me


Thanks in advance
Posted
Comments
ManavGuru 10-May-12 4:36am    
you should be debug your code then u can know where is fault
Sandeep Mewara 10-May-12 4:44am    
You saying that above code is getting executed and working fine on your system but it is not giving the desired result even though the code runs there? Or the code itself dont run in other system?
DeepakThukral 10-May-12 5:13am    
It is not giving the desired output on another systems

it is not getting check box value on another systems, when i try to check value using alert then it shows 'Nan' value

1 solution

JavaScript
var chklst = chk.parentNode.parentNode.parentNode;


Maybe that's what makes the problem when transferring the code to another HTML page.
Try to check the hierarchy of controls if it still the same.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900