Click to See Complete Forum and Search --> : Need help with document.write


jgarrison
12-18-2002, 09:10 PM
I write a cookie with a user's first and last name as entered in my member database. When someone returns to the home page I read the cookie to write their first and last name on the page.

function who(info){
var fname = GetCookie('fname')
var lname = GetCookie('lname')
return fname + " " + lname;
}


document.write(Who());


Problem is some people enter a middle initial or suffix with their name in the database like John S. Doe, and it prints on the page like this: John S.+Doe

How can I get rid of the + sign?

khalidali63
12-18-2002, 09:24 PM
A simple solution would be use of a JavaScript String function ,something like this
lname.replace(/+/,"");

the problem though it will only work with browsers that support JavaScript 1.3 and higher

Khalid

jgarrison
12-18-2002, 11:54 PM
I replaced
return fname + " " + lname;
with
return fname.replace(/+/," ") + " " + lname.replace(/+/," ");
and nothing at all is written to the page.

Do I have the syntax incorrect? I'm using IE6.

Thanks.