When a person clicks on a link, I want to do this:
The problem with appending something to window.location.href
is what if you have already done that? You'll just keep appending "?search=..."
multiple times. More importantly, it's more complicated than it needs to be.
You're already using jQuery. Why not just do this?
<form id="search" method="get">
<input type="text" name="search">
</form>
<a href="#" id="go">Search</a>
with:
$(function() {
$("#go").click(function() {
$("#search").submit();
return false;
});
});
and then you don't have to worry about the right URL, encoding, etc.
How about:
window.location = "/currentpage.aspx?search=" + escape( $("#someId").val());
or
window.location = window.location.pathname + "?search=" + escape( $("#someId").val());
Etc...
What part isn't working?
Try encodeURI() rather than escape().
window.location.href = window.location.href + "?search=" + escape( $("#someId").val());
?
$("a").click(function() {
document.location.href += "?search=" + encodeURIComponent($("#myTextBox").val());
});
You are changing the wrong location property if you only want to change the search string. I think you want to do this:
location.search = "?search=" + encodeURIComponent( $("#someId").val());