Jump to content

embedding Javascript code into HTML code someone help explain how I would modify


Minimeallolla

Recommended Posts

Can someone help explain to me how I would go about embedding a javascript clock/time function code into a html submit form?

 

Ok so this cookie asks for a username through a pop up on connection, I would rather use the information submitted by a username form instead and use it as a php cookie.

 

		// COOKIE FUNCTION STARTS HERE \\
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function checkCookie()
{
var username=getCookie("username");
if (username!=null && username!="")
  {
  alert("Welcome again " + username);
  }
else 
  {
  username=prompt("Please enter your name:","");
  if (username!=null && username!="")
    {
    setCookie("username",username,365);
    }
  }
}
		// COOKIE FUNCTION STOPS HERE \\

 

Do you mean you just want to have a timestamp of the time that the user submitted the form?

I'd handle that on the server side when the form is submitted. 

 

Otherwise, if you need to get the date/time, it depends on what format you need, and there's 100 ways to skin a cat.

The basic premise is simple:

new Date().getTime(); 

Will return the timestamp in UNIXTIME format which is nice and easy to do date/time calculations with

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.