Script Categories













Forms >>> Smart Pulldown Menu.

Uses cookies to let a dropdown list remember which option was chosen when a user returns to the page. It comes in very handy if you have a page that is frequently accessed and users tend to repeatedly chose the same option from a list.

Just make a selection then refresh this page.

Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
var expDays = 30; // set this value to however many days you want your cookies to last
function setCookie(name, val) {
var exp = new Date();
var cookieTimeToLive = exp.getTime() + (expDays * 24 * 60 * 60 * 1000);
exp.setTime(cookieTimeToLive);
document.cookie = name + "=" + escape(val) + "; expires=" + exp.toGMTString();
}
function getCookie(name) {
var cookieNameLen = name.length;
var cLen = document.cookie.length;
var i = 0;
var cEnd;
var myStringToReturn;
var myStringToReturnLen;
while (i < cLen) {
var j = i + cookieNameLen;
if (document.cookie.substring(i,j) == name) {
cEnd = document.cookie.indexOf(";",j);
if (cEnd == -1) {
cEnd = document.cookie.length;
}
myStringToReturn = unescape(document.cookie.substring(j,cEnd));
myStringToReturnLen = myStringToReturn.length;
myStringToReturn = myStringToReturn.substring(1,myStringToReturnLen+1);
return myStringToReturn;
}
i++;
}
return "";
}
function setDefaultValues() {
var strCookieName, strCookieVal;
var iFormsCount = 0;
var iElementsCount = 0;
for(iFormsCount=0;iFormsCount < document.forms.length;iFormsCount++) {
for(iElementsCount=0; iElementsCount < document.forms[iFormsCount].elements.length; iElementsCount++) {
strCookieName = document.forms[iFormsCount].elements[iElementsCount].name;
strCookieVal = getCookie(strCookieName);
if (strCookieVal != null && !(isNaN(strCookieVal)) && strCookieVal != '') {
document.forms[iFormsCount].elements[iElementsCount].selectedIndex = strCookieVal;
         }
      }
   }
}
window.onload=setDefaultValues;
//  End -->
</script>
<form>
<select
name=select onChange="setCookie(this.name,this.selectedIndex)">
<option>
Choice 1</option>
<option>
Choice 2</option>
<option>
Choice 3</option>
<option>
Choice 4</option>
</select>
</form>
Just make a selection then refresh this page.

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.



Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).

Bitcoin Gambling Site


©