Thank you for your help. The global flag seemed to do the trick, if I
get problems with that in the future I will try the encodeURIComponent
method.



On Aug 5, 9:42 pm, Karl Swedberg <k...@englishrules.com> wrote:
> Hi there,
>
> It looks like your test:
>
> > var test = searchval.text().replace(' ','+');
>
> is trying to use the .text() jQuery method on a string. Remove that  
> part and it should work, sort of. It'll only replace the first  
> instance of a space. Instead, use the regex replace and set the global  
> (g) flag:
>
>         var test = searchval.replace(/ /g,'+')
>
> But that isn't much better. What you really ought to use is  
> encodeURIComponent:
>
>         var test = encodeURIComponent(searchval);
> see how that works.
>
> --Karl
>
> ____________
> Karl Swedbergwww.englishrules.comwww.learningjquery.com
>
> On Aug 5, 2009, at 5:00 AM, MiKiTiE wrote:
>
>
>
> > 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.

Reply via email to