I'm trying to switch back and forth between two different modes in my website. One mode is "Grid" and the other is "List". So in the url it would be www.example.com/index.php?mode=grid and when you click on a specific link it would change the mode to list. My code only takes it from index.php to one of the queries once;
The Javascript:
function gridclick(){
if(location.href.match(/\?mode=/)){
var reExp = /mode=\d+/;
var url = window.location.toString();
var newUrl = url.replace(reExp, "mode=" + "grid");
}
else{
window.location="index.php?mode=grid";
}
}
function listclick(){
if(location.href.match(/\?mode=/)){
var reExp = /mode=\d+/;
var url = window.location.toString();
var newUrl = url.replace(reExp, "mode=" + "list");
}
else{
window.location="index.php?mode=list";
}
}
The HTML:
<img src="images/grid.png" width="18" height="18" alt="Grid view" onClick="gridclick()"/>
<img src="images/list.png" alt="List view" width="18" height="18" onClick="listclick()"/>
newUrl?window.location = newUrl;to both but it wont change after being clicked the second time.