[jQuery] Replace string characters using jQuery

[jQuery] Replace string characters using jQuery


Hi Everyone
First post - please be gentle.
I am running a search on my web site which uses jQuery to take the
search terms and build up a URL based on them.
For example, if someone searches for "chair" my URL will be appended
with /chair/.
However, if someone searches for something which is two words, for
example "chair covers" I need the space inbetween to be replaced by a
"+" sign so the URL will now be appended with /chair+covers/
I'm not sure if it is possible to string replace in jQuery? Here is my
current code:
function sendSearchInput(whichelement,hiddeninput,formid) {
hval = $("#"+hiddeninput).val();
$("#"+formid).submit(function() {
    if ($("input:#"+whichelement).val() != hval) {
        var searchval = $("#"+whichelement).val().toLowerCase();
        $("#"+formid).attr("action","retail/search/"+searchval+"/");
            return true;
    }
     $("input:#"+whichelement).focus();
return false;
});
}
This will basically check that the form is not the default value
(specified in the hidden field "hval") and then change the search term
to lowercase and append the URK using "attr". I have tried a couple of
methods including
var test = searchval.text().replace(' ','+');
And then trying to alert "test" to check it but the function just
simply doesn't work.
Any help here would be much appreciated, thank you.