homepage Welcome to WebmasterWorld Guest from 174.129.163.183
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Home / Forums Index / WebmasterWorld / New To Web Development
Forum Library, Charter, Moderators: brotherhood of lan & mack

New To Web Development Forum

    
Need help editing a save cookie javascript code
cffrost2




msg:3864740
 12:03 am on Mar 7, 2009 (gmt 0)

I have an employee page that uses a javascript to save a cookie on body unload in order to save entered drawer count fields. It's a snip that was free from a website. Great. Works as needed. But you can only edit the amount of days till it expires the cookie file. I need to be able to edit it down to the minute if possible. I don't want them to use it everyday keeping them from having to count their cash drawers.

Please take a look and tell me what I need to change to be able to edit the time in hours and minutes also rather than just days.

[b]var remembervalues_days=1 //Remember text input values for how many days?[/b]
var dyncookiename=encodeURI(window.location.pathname) //Name of cookie. Changes depending on the page.
.....
var recallinput=function(){
var cookienamevalue=rememberinput.getCookie(dyncookiename).split("##")
for (var i=0; i<cookienamevalue.length; i++){
var cookiename=cookienamevalue[i].split("#")[0]
var cookievalue=cookienamevalue[i].split("#")[1]
if (document.getElementById(cookiename)!=null && document.getElementById(cookiename).type=="text") //if this text field has a stored value
document.getElementById(cookiename).value=decodeURI(cookievalue)
}
}
.....
var rememberinput=function(){
var rememberit=""
for (var i=0; i<arguments.length; i++){
if (document.getElementById(arguments[i]).type=="text" && document.getElementById(arguments[i]).value!="") //if this is a form text INPUT and not empty
rememberit+=arguments[i]+"#"+encodeURI(document.getElementById(arguments[i]).value)+"##"
}
rememberinput.setCookie(dyncookiename, rememberit, remembervalues_days)
}
.....
rememberinput.getCookie=function(Name){ //get cookie value
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}
.....
rememberinput.setCookie=function(name, value, days){ //set cookie value
var expireDate = new Date()
//set "expstring" to either future or past date, to set or delete cookie, respectively
var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+";";
}
.....
if (window.addEventListener)
window.addEventListener("load", recallinput, false)
else if (window.attachEvent)
window.attachEvent("onload", recallinput)
else if (document.getElementById)
window.onload=recallinput

Thanks a lot.
Kevin

 

cffrost2




msg:3866283
 2:20 pm on Mar 9, 2009 (gmt 0)

Anyone? Please...

coopster




msg:3866327
 3:20 pm on Mar 9, 2009 (gmt 0)

If all is working well for you but you merely want to adjust from days down to minutes you need to add the time value to the cookie setting and modify the code to compare the time as well.

cffrost2




msg:3866459
 5:46 pm on Mar 9, 2009 (gmt 0)

Thanks for your reply. I've been working in php and need this for my page. I don't really know javascript. I am hoping someone could show me what to edit. Sorry I wasn't more clear

Thanks.

cffrost2




msg:3866668
 9:07 pm on Mar 9, 2009 (gmt 0)


If all is working well for you but you merely want to adjust from days down to minutes you need to add the time value to the cookie setting and modify the code to compare the time as well.

I understand what you said , I just don't know how to do that. I see the line...

var remembervalues_days=1 //Remember text input values for how many days?

But have no idea how to change it from days to minutes. I just want it to save for 10 minutes for now unless I use it for something else and need it for days or months.
Thanks for any help you can give.
Kevin

cffrost2




msg:3869800
 4:53 pm on Mar 13, 2009 (gmt 0)

Can anyone help me with this?

Thanks
Kevin

coopster




msg:3869869
 6:30 pm on Mar 13, 2009 (gmt 0)

You simply need to use time values rather than date values. The JavaScript reference describes how to get and set date and time values. The Mozilla help docs are a good reference:
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / New To Web Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved