Getting variable value out of jQuery
<p>Is there any way to extract value of a variable used in jQuery so that we can use it in JavaScript functions</p>

<pre><code>&lt;script&gt;
var val;
$(document).ready(function() {$('.nav a').click(function(event) 
{event.preventDefault();
val=$(this).index();

if(val==0){

$('#hide_main').hide();
$('.main_BSNS').animate({opacity:"show",height:"400px"},'slow')                                             


                    }//if val==0 ends here

                else if(val==1){

                    $('#hide_main').hide();
                    $('.main_ACTNT').animate({opacity:"show",height:"400px"},'slow')                                                

                    }

                else if(val==2){

                    $('#hide_main').hide();
                    $('.main_devp').animate({opacity:"show",height:"400px"},'slow')                                             


                    }




            });



        });
function getCookie(c_name){
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i&lt;ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}

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 checkCookie()
{
var username=getCookie("BSNS");
if (username!=null &amp;&amp; username!="")
{
$('#hide_main').hide();
$('.main_BSNS').animate({opacity:"show",height:"400px"},'slow')
}

else
{
alert(val);
if (username!=null &amp;&amp; username!="")
{
setCookie("BSNS",username,365);
$('#hide_main').hide();
$('.main_BSNS').animate({opacity:"show",height:"400px"},'slow')
}
}
}   
&lt;/script&gt;
</code></pre>

<p>now i want this checkCookie() function to be called by  but the alert always show up with an undefined value (as many users predicted) but i am unable to find a solution to this and to write these cookies...(finally i am successful atleast to put my code on this website :-) )</p>
