/search.aspx?Search=test
function getQuery(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
};
if (getQuery('SearchType') == '') {
$("#txtSearch").val(getQuery('Search'));
};
if I leave out the if statement and just set the value of the textbox it works fine, so I obviously know my getQuery function is working. It’s obviously something to do with the fact that SearchType is NOT ”, it’s not anything. I tried “if (getQuery(‘SearchType’)) but that didn’t work either.
Must be a simple answer… there always is to my questions 🙂
It’s because you’re comparing to an empty string, but
getQueryis returning null. Change your comparison to this: