+ Start a Discussion
SharathChandraSharathChandra 

How to set dependent pick list value by cookies from java script

Page:

====

<apex:page standardController="Case">
<script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>
<apex:form id="fid">
<apex:pageBlock id="pbid">
<apex:pageBlockSection id="pbsid">
<apex:inputField value="{!Case.Product_Family__c}" id="pfid"/>
<apex:inputField value="{!Case.Product__c}" id="pid"/>
Remember Me:<input type="checkbox" value="1" name="rememberId" id="rememberId" />
</apex:pageBlockSection>
<apex:pageBlockButtons >
<!--<apex:commandButton value="Save" action="{!save}" id="btn"/>-->
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
<script>
$(document).ready(function(){
checkCookie();
$("#rememberId").click(function()
{
alert('hi');
var thisCheck = $(this);
if (thisCheck.is(':checked'))
{
alert('checked');
saveUserInfo();
}
});

});
</script>

<script>
function getCookie(c_name)
{
var nameEQ = c_name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0){
var subStr=c.substring(nameEQ.length,c.length);
return unescape(subStr);
}
}
return null;
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function saveUserInfo(){
if(document.getElementById("rememberId").checked == true) {
//set elements
setCookie("rememberId",1,365);
setCookie("product_family",document.getElementById("{!$Component.fid.pbid.pbsid.pfid}").value,365);
setCookie("product",document.getElementById("{!$Component.fid.pbid.pbsid.pid}").value,365);
}
else
{
//erase cookies
eraseCookie("rememberId");
eraseCookie("product_family");
eraseCookie("product");
}
}
function eraseCookie(name) {
setCookie(name,"",-1);
}

function checkCookie()
{
var remembered = getCookie("rememberId");
if(remembered == 1){
//alert('in check cookie');
//alert(getCookie("product_family"));
$("[id$=pfid]").val(getCookie("product_family"));
//alert(getCookie("product"));
$("[id$=pid]").val(getCookie("product"));
// document.getElementById("{!$Component.fid.pbid.pbsid.pfid}").value = getCookie("product_family");

}
}
</script>
</apex:page>

 

here i'm not able to set value for product field.

Please help asap