0

code:

I have created an autocomplete suggestion box which is completely fine. Now, I have redirect my selected item from autocomplete to url and my url look like

mywebsite.com/search.php?aa=Admission%20support

here I want to replace %20 with - operator sign after that my url look like

mywebsite.com/search.php?aa=Admission-support

So, How can I do this ?please help me.

<script>
    $(function() {
        $( "#show" ).autocomplete({
            source: 'search-result.php',
            minLength:2,
            select: function(event, ui) 
            {
                x = ui.item.value;
                y = x.replace(/%20/g, "-");
                location.href = "search.php?aa="+y;
                return false;
            }
        });
    });
</script>

Thank You

2
  • Why not solve that server side in your 'search-result.php' file? Commented Oct 6, 2017 at 6:14
  • you have solved it yourself. :/ do you asking on how to receive the $_GET['aa'] in PHP with "-" replaced with " "? Commented Oct 6, 2017 at 6:14

1 Answer 1

1

%20 is not encoded from -. Javascript has a built-in function to decode:

console.log(
  decodeURI("mywebsite.com/search.php?aa=Admission%20support")
);

Refer w3schools for more information.

Sign up to request clarification or add additional context in comments.

4 Comments

I have done buddy take a look <script> $(function() { $( "#show" ).autocomplete({ source: 'search-result.php', minLength:2, select: function(event, ui) { var x = ui.item.value; y = encodeURIComponent(x); z = y.replace(/%20/g, "-") location.href = "search.php?aa="+z; return false; } }); }); </script>
Thank you mate for your help :)
Of course, because your are replacing %20 with -

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.