Jump to content

Capitalizenames Cookie?


paulmo

Recommended Posts

Yes in development (not live) I've got first name cookie. If I don't capitalize it reads "Hello paul!" which is pretty amateurish. I want "Hello Paul!" Here's code if you might please advise where to modify:

function getCookie(c_name){if (document.cookie.length>0)  {  c_start=document.cookie.indexOf(c_name + "=");  if (c_start!=-1)	{ 	c_start=c_start + c_name.length+1;	c_end=document.cookie.indexOf(";",c_start);	if (c_end==-1) c_end=document.cookie.length	return unescape(document.cookie.substring(c_start,c_end));	}   }return ""}function setCookie(c_name,value,expiredays){var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString());}function checkCookie(){name=getCookie('name');//name=CapitalizeNames('name');if (name!=null && name!="")  {  alert('Hello '+name+'!');  }else   {  name=prompt('Please introduce yourself by entering your name or nickname:',"");  if (name!=null && name!="")	{	setCookie('name',name,365);	}  }}

Link to comment
Share on other sites

All you really need to do is create a capitalize() function and use it. I gave you the reference to string functions before, here is how to use them.

function capitalize(str) {  firstLetter = str.substr(0,1);  remainingString = str.substr(1);  return firstLetter.toUpperCase() + remainingString}

To use the function, you would just do this:

capitalize(name);

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...