Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
function FunValidation() 
{
            TxtName = document.getElementById('<%= TxtName.ClientID %>');
            ChkBranch = document.getElementById('<%= ChkBranch.ClientID %>');
            var HdnMode = document.getElementById('<%= HdnMode.ClientID %>');
            var rows = ChkBranch.getElementsByTagName('input');
            var Firstid = rows[0].id;
            var Intcount = 0;
            var IntCheckBranch = 0;

            if (HdnMode.value != 'D') {
                for (var i = 0; i < rows.length; i++)
                {
                    var id = rows[i].id;
                    if (document.getElementById(id).checked == true) {
                        Intcount = 1
                    }

                    if (HdnMode.value == "N")
                    {
                        DDLBranch = document.getElementById('<%= DDLBranch.ClientID %>');
                        if (document.getElementById(id).checked == true)
                        {
                            if (document.getElementById(id).value == DDLBranch.value)
                            {
                                IntCheckBranch = 1
                            }
                        }
                    }
                }
}


Here i am getting a value of
JavaScript
document.getElementById(id).value


is "on" insted of its original selected Value..so i am getting my validation error...plzz help me..
i am trying to solve this error since a week..but didnot get solution...

so my question is why i am getting checkbox list values "on"??


ASP.NET
<asp:CheckBoxList ID="ChkBranch" runat="server" AutoPostBack="True" DataTextField="Name"
                                                       DataValueField="id" meta:resourcekey="ChkBranchResource1" Style="margin: 15px;"
                                                       OnSelectedIndexChanged="ChkBranch_SelectedIndexChanged">
                                                   </asp:CheckBoxList>
Posted
Updated 22-Dec-14 23:21pm
v2
Comments
Kornfeld Eliyahu Peter 23-Dec-14 4:50am    
Can you show the markup? I'm interested in how you assigned the value to the checkbox...
Praveen Kumar Upadhyay 23-Dec-14 5:02am    
I did not get, what is the link of the codes you have mentioned.
Mayur Ahir 23-Dec-14 5:22am    
yes sure...see updates
Kornfeld Eliyahu Peter 23-Dec-14 5:24am    
Every click on your checkbox initiate a post-back to your page, that can clear all the state of the page...
How do you call the validation function?
Tushar sangani 23-Dec-14 5:25am    
You get value jquerry or code behind ?

1 solution

If You Get Value By jquerry Code Like Below on Button Click


$("#demo").click(function () {
var selectedValues = [];
$("[id*=ChkBranch] input:checked").each(function () {
selectedValues.push($(this).val());
});
if (selectedValues.length>0) {
alert("Selected Value(s): " + selectedValues);
} else {
alert("No item has been selected.");
}
});

OR
CheckBoxlist Check Or Click Like Below

if jQuery >= 1.7

$('#ChkBranch').on('click', ':checkbox', function() {
if ($(this).is(':checked')) {
// handle checkbox check
alert($(this).val());
} else {
// checkbox is unchecked
alert('unchecked')
}
});


You can register a click event handler for all the checkboxes, inside the event handler this will point to the clicked checkbox

if jQuery >= 1.7

$('#ChkBranch').on('click', ':checkbox', function() {
if ($(this).is(':checked')) {
// handle checkbox check
alert($(this).val());
} else {
// checkbox is unchecked
alert('unchecked')
}
});
if jQuery < 1.7

$('#ChkBranch:checkbox').live('click', function() {
alert($(this).is(':checked'));
});
 
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