/    Sign up×
Community /Pin to ProfileBookmark

Need help getting value from cookie

I’ve got a form that has an input that I want to autopopulate when the user selects a value on another input. The value I want to put in comes from a cookie. Here’s the code I have:

[CODE][function UpdateStatus(){
var objDate = new Date()
var strTemp = “”

if(document.getElementById(“statuslist”).value == “Closed”){
// Update CloseDate
if(document.getElementById(“CloseDate”).value == “”){
strTemp = (objDate.getMonth() + 1) + “/” + objDate.getDate() + “/” + objDate.getFullYear()
document.getElementById(“CloseDate”).value = strTemp
}
}
// Update Close User
if(document.getElementById(“CloseUser”).value == “”){
if(GetCookie(“USER”) != null && GetCookie(“USER”) != “” )
{document.getElementById(“CloseUser”).value = getCookie(“USER”)}
else
{document.getElementById(“CloseUser”).value = document.getElementById(“EditBy”).value}
}
}[/CODE]

This function is run via an “onchange” event tied to a drop down list. The first part actually works and the time/date gets filled in. It’s the second part where I’m trying to pull a value from a cookie that fails. The value does exist and I have no problem calling the value using ColdFusion’s cookie handling tags. I’m very inexperienced with JS, so I’m not quite sure where I’ve gone wrong.

Thanks!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@WebnerdOct 10.2007 — Check your case:

GetCookie vs getCookie
Copy linkTweet thisAlerts:
@ThraxenauthorOct 10.2007 — I've had it lower case initially, but then I saw an example on the web that had it upper case so I tried that. To double check though, I just changed it back to getCookie and it still fails. I'm getting an "Object Expected" error on this line:

if(getCookie("USER") != null && getCookie("USER") != "" )
Copy linkTweet thisAlerts:
@ThraxenauthorOct 10.2007 — Well, I solved my problem by using an alternate solution. Instead of try to use JS to read a cookie value (which I could not figure out), I created a hidden input on my form and set its value to the value in the cookie I wanted using ColdFusion. I then used this in the JS code:

[CODE]if(document.getElementById("CloseUser").value == ""){
if(document.getElementById("CurrentUser").value != "")
{document.getElementById("CloseUser").value = document.getElementById("CurrentUser").value}
else
{document.getElementById("CloseUser").value = document.getElementById("EditBy").value}
}[/CODE]


"CurrentUser" is the name of the hidden input on my form.
×

Success!

Help @Thraxen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...