Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Space disappearing in Cookie 1

Status
Not open for further replies.

Papa Bear

Programmer
Feb 1, 2003
37
GB
Hi All
I am trying to store a string in a cookie with a space in i.e. "abc 123". When I retrieve the string, the space has gone i.e."abc123". This is the code used to store.
Code:
<script type="text/javascript">

function BlurName() {
    alert("hello" + document.getElementById("IdSearch").value)
    document.cookie = "CustName=" + document.getElementById("IdSearch").value;
}

</script>
I have an onblur to call this function on text box IdSearch. The alert statment is for test and displays the string correctly.

I read the cookie like this.
Code:
<%
response.write "Search = " & request.cookies("CustName")
%>
And the space has gone!!!
Could it be the mixture of javascript and ASP?

Thanks in advance
Steve
 
Spaces are delimiters in cookie values

Add quote marks to the value before storing it.
OR
URLEncode the value before storing in in the cookie
OR
replace the space with '+' (this is what seach engine do)

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Hi Chris.

Thanks for that. I used encode and it worked a treat.

Do I need to close this thread? Can not see any way to do that.

Thanks again.
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top