Click here to Skip to main content
16,012,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have dropdown checkbox with data binded dynamically.I pass value through cookie then the value equal to the dropdown checkbox it checked.For example
JavaScript
$(document).ready(function () {
//binding dropdown checkbox code, after that

var cookievalue= getCookie("Cookieval");
        if (cookievalue!= null) {

            $(window).bind("load", function () {
                    $("input[id='dropdownchecklistid'][value='" + cookievalue+ "']").prop("checked", true);
                    
            });

        }
});

But it doesn't work first time loading the page

What I have tried:

I have tried window.load also but I didn't get proper result.May be it works second time is after creating cache.
Posted
Updated 7-Jun-16 2:51am
Comments
So, if the cookie does not exist, then it won't work.
Dil0500 30-May-16 13:16pm    
It's not related to cookie .Cookie working fine
Libin C Jacob 31-May-16 1:44am    
Is your script code reside inside the the header part or body part. You just put the script just before your body closing (</body>). It may work. All the best.

1 solution

try
JavaScript
if (cookievalue!= null) 
{
    $("input[id='dropdownchecklistid']").val(cookievalue).prop("checked",true);
}
 
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