HighDots Forums  

Default Function Value from a Cookie

Javascript JavaScript language (comp.lang.javascript)


Discuss Default Function Value from a Cookie in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
evanburen@gmail.com
 
Posts: n/a

Default Default Function Value from a Cookie - 03-01-2006 , 10:44 AM






When my page loads, I check for the existence of a cookie value through
readCookie(). If there is a value present for the cookie, I would like
that to be the default value in function ordering() and that value to
be the SELECTED value in ddlProfileNames. In other words, if there is
no cookie value, then function ordering will default to
ordering("Div1,Div2,Div3,Div4"). If there is a value, then that should
be used in function ordering and as the default value in
ddlProfileNames. Thanks for any help.

<body onLoad="readCookie('default')">

<FORM name="frmProfileNames">
<SELECT class="smalltext" id="ddlProfileNames"
onChange="ordering(this.options[this.selectedIndex].value);">
<option value="Div1,Div2">1 & 2</option>
<option value="Div3,Div4">3 & 4</option>
<option value="Div1,Div2,Div3,Div4" SELECTED>All Sections</option>
</SELECT>
<a href="#" onclick="setCookie('default', 30);return false">Save as
Default Profile</a>
</FORM>


<SCRIPT>
function ordering(sorder)
{
// code here
}

// start things off:
ordering("Div1,Div2,Div3,Div4");

</SCRIPT>


Reply With Quote
  #2  
Old   
Stephen Chalmers
 
Posts: n/a

Default Re: Default Function Value from a Cookie - 03-01-2006 , 07:49 PM







evanburen (AT) gmail (DOT) com wrote:
Quote:
When my page loads, I check for the existence of a cookie value through
readCookie(). If there is a value present for the cookie, I would like
that to be the default value in function ordering() and that value to
be the SELECTED value in ddlProfileNames. In other words, if there is
no cookie value, then function ordering will default to
ordering("Div1,Div2,Div3,Div4"). If there is a value, then that should
be used in function ordering and as the default value in
ddlProfileNames. Thanks for any help.

If the cookie has a value, loop through all the values in the select
and compare
them to the cookie's value. If a match is found, set the selectedIndex
property
to the current value of the loop counter and optionally call
ordering(), passing the currently indexed value as the parameter.

--
S.C.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.