CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Need Some Help With a cookie..

 



theworkz
Deleted

Jun 4, 2000, 11:27 AM

Post #1 of 3 (461 views)
Need Some Help With a cookie.. Can't Post

I have one more question for you guys. Shouldnt be too hard.. its not really perl related but if you know please let me know..
Im writing cookies using Javascript. I have a text field that i want information to be stored and also retrieved if it exists.. this is what i have that works..

<INPUT TYPE="text" NAME=zip SIZE="5" onFocus="getValue(this)" onBlur="setValue(this)" VALUE="">

This seems to workfine but the information only comes up when i click the field box. I want it to come up when the page loads.. i dont want them to have to click in the box. ive tryed onLoad but that doesnt seem to work..the Onblur is fine for storing info but i need to it pull up automatically.. I have the head of the Javascript if you guys need that to troubleshoot with..

Thanks in advance.

Luke Ross


DrZed
User

Jun 4, 2000, 3:25 PM

Post #2 of 3 (461 views)
Re: Need Some Help With a cookie.. [In reply to] Can't Post

Need help with a cookie? Try dunking it in milk. That will fix all but the most stubborn cookie.

Seriously, what you need to do is to define the VALUE. Currently, you have VALUE="". That means that it will start blank. If you can fill in that value, somehow, you will get what you want.

I don't know JavaScript, so how you can get the value you want there is beyond me. Perhaps something as simple as VALUE=getValue(this), but I'm guessing that all you would get is that exact text in the field.

It's worth a shot....


theworkz
Deleted

Jun 4, 2000, 4:59 PM

Post #3 of 3 (461 views)
Re: Need Some Help With a cookie.. [In reply to] Can't Post

nope.. that didnt work.. lemme give you the rest of the code for the cookie.. this is in the <head> of the page (with explanations)
------------------------------------
<SCRIPT LANGUAGE = "JavaScript">
<!--

// Use this function to retrieve a cookie.
function getCookie(name){
var cname = name + "=";
var dc = document.cookie;
if (dc.length > 0) {
begin = dc.indexOf(cname);
if (begin != -1) {
begin += cname.length;
end = dc.indexOf(";", begin);
if (end == -1) end = dc.length;
return unescape(dc.substring(begin, end));
}
}
return null;
}

// Use this function to save a cookie.
function setCookie(name, value, expires) {
document.cookie = name + "=" + escape(value) + "; path=/" +
((expires == null) ? "" : "; expires=" + expires.toGMTString());
}

// Use this function to delete a cookie.
function delCookie(name) {
document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
}

// Function to retrieve form element's value.
function getValue(element) {
var value = getCookie(element.name);
if (value != null) element.value = value;
}

// Function to save form element's value.
function setValue(element) {
setCookie(element.name, element.value, exp);
}

var exp = new Date();
exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 31));

//-->
</SCRIPT>
---------------------------

and here is the form for getting and recieving data from the cookie..

---------------------------
<FORM METHOD="POST" ACTION="http://www.whatever.com/cgi-bin/search.pl" onSubmit="submitonce(this)">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" BGCOLOR="#FFFFFF">
<TR>
<TD><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" bgcolor="#FFFFFF">
<TR><TD ALIGN="center" VALIGN="middle">
<INPUT TYPE="text" NAME=zip SIZE="5" onFocus="getValue(this)" onChange="setValue(this)" VALUE="" STYLE="font-family:Courier New;font-size:10pt;"><INPUT TYPE="submit" VALUE="Get It" WIDTH="120"></TD>
</TR></TABLE></TD>
</TR>
</TABLE>
</FORM>

----------

look at past messages for what im trying to do..

thanks in advance
Luke

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives