I'll start out by giving you the code I'm working on so that you can follow what I'm saying (sorry for the french, I realise all of you don't speak french but I'm making this website for a french-speaking school). I've edited out what I don't think is part of the problem (the actual file is 757 lines long!)
photos.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Photos</title>
<script type="text/javascript">
function removeCriterion(criterionText)
{
var getData = new RegExp("&" + criterionText + "|\\?" + criterionText + "$|" + criterionText + "&", "gi");
window.location = window.location.toString().replace(getData,"");
}
</script>
</head>
<body>
<a class="retirerCritere" onclick="removeCriterion('Shawn+Freyssonnet-Inder');" title="Réessayer la recherche sans ce critère"><img src="img/deleteButton.png" alt="Retirer" /></a>
</body>
</html>
Although it doesn't look like much with all the extras stripped out, this is part of a page which displays photos based on a set of criteria. These criteria are fetched through php variable $_GET, so if I want to show all the photos that belong to me (Shawn Freyssonnet-Inder) and which were taken in France, I use the following link:
<a href="photos.php?nom=Shawn+Freyssonnet-Inder&pays=France" ...>link</a>
This page then fetches all photos for which nom = Shawn Freyssonnet-Inder and pays = France in a mysql database. In addition, it shows the user the list of criteria used to filter the results, allowing him (her) to isolate a criterion, remove a criterion, etc.
note: The space is replaced with a plus sign (+) with php function urlencode. I remove the plus sign using urldecode before showing the txt on the page, making sure the user has the appropriate human-friendly version of the string. Now when I call the removeCriterion function, I use the same urlencoded string as argument so I believe there should be no problem for javascript in finding the text in the url.
My problem occurs when trying to remove a criterion. As you can see, I remove criteria with the removeCriterion javascript function, which simply finds the criterion definition in the url and removes it (find and replace). But for some reason, on certain criteria, it doesn't work, such as "Shawn Freyssonnet-Inder" or other strings with spaces.
Would any of you know why javascript can't find and replace strings containing spaces in the url?