0

I have a Javascript function that sets a cookie and reloads the page from the server, I use this to handle changes to the selection criteria, it works well, however I just found a weird problem that I can't explain.

My function is as follows:

<script>
function reloadfunc(xcookiename,xvalue)
{
// Set cookie
document.cookie=xcookiename + "=" + xvalue+";path=/";
// Force scroll to top of page
document.cookie="scroll-to-top=Y;path=/";
// Reload Page from server
location.reload(true); 
}
</script>

When I pass in a value of "{Blade Length|100mm+}" the cookie value ends up as "{Blade Length|100mm}" - the "+" has been stripped off for some reason.

Any thoughts on what I am doing wrong and how to fix it please?

I could understand if for some reason the "+" had vanished off the end of the string value, but it's in the middle of the string.

Tony Payne
  • 382
  • 2
  • 10
  • 1
    I wasn't able to reproduce this. Can you post a JSFiddle that demonstrates this behaviour? It would also be helpful if you told us what browser you're seeing this in. – freshtop Jun 12 '14 at 07:25
  • I just found more details about the problem, I am using Firefox 30.0. It doesn't look like it's Javascript, it's the Cookies. In Firebug I set the value of a cookie to "{Blade Length|100mm+}", but it shows as "{Blade Length|100mm}". When I go to change the value it's as I entered it, but when I just display the cookie values the "+" shows as a space. I am trying to see if I can find why this might happen and if it's browser specific. – Tony Payne Jun 12 '14 at 08:00
  • Seems that this is a common problem, one that I haven't come across before certainly. One (of many) posts is http://stackoverflow.com/questions/14383715/why-does-php-replace-pluses-with-spaces-in-cookie . I guess that answers my question, it's PHP/Cookies. Now to find an answer... – Tony Payne Jun 12 '14 at 08:09

0 Answers0