Javascript - Replace more than one value

Kokox

I have a problem with my script. I want to replace all spaces with +.

The script works with the first space, e.g. for Crazy dog:

Crazy+dog

But with a third word it does no longer work, e.g. for Crazy dog cat:

Crazy+dog cat

I'm using the following JavaScript code:

function search() {
    location.href = 'buscar/'+document.getElementById('appendedInputButton').value.replace(' ','+');
}

I searched how to do it, but nothing works me, I have not much experience with JavaScript.

Edit:

Sorry for the repost, I tried using the / ... / but it did not work as expected. Now I know, I should be working more with encodeURI.

eltyweb

The best way is to use regular expression with g flag to replace all occurrences.

<script type='text/javascript'>
    function search()
    {
        location.href = 'buscar/'+document.getElementById('appendedInputButton').value.replace(/\s+/g, '+');
    }
</script>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Taking means of more than one value

From Dev

Javascript Regex for Decimal Numbers - Replace non-digits and more than one decimal point

From Dev

Storing more than one value into Isolated Storage

From Dev

Subsetting rows selecting on more than one value

From Dev

Replace strings with more than one character

From Dev

More than one value in rel and access using javascript or jquery

From Dev

Pandas: Apply(): Return more than one value

From Dev

Return more than one value from a function

From Dev

More than one maximum value in SQL

From Dev

Submit more than one value to database

From Dev

Replacing more than one elements with replace function

From Dev

Selecting more than one value without checkboxes

From Dev

JavaScript: Arguments with more than one value

From Dev

Pivot / crosstab with more than one value column

From Dev

More than one value returned by subquery

From Dev

replace more than one pattern python

From Dev

Javascript incrementing by more than one

From Dev

How to remove more than one whitespace from a string in javascript(Can not use regex replace function)?

From Dev

VLOOKUP more than one value

From Dev

get check box value with javascript and add those values in a div as i select more than one value

From Dev

Replace strings with more than one character

From Dev

More than one value in rel and access using javascript or jquery

From Dev

Javascript regex : replace more than one forward slashes with only one slash

From Dev

replace more than one special character with sed

From Dev

Replacing more than one elements with replace function

From Dev

Selecting more than one value

From Dev

Javascript incrementing by more than one

From Dev

How to replace more than one fragments with another one in the back stack?

From Dev

JAVASCRIPT How to get More than one value in Select Option

Related Related

  1. 1

    Taking means of more than one value

  2. 2

    Javascript Regex for Decimal Numbers - Replace non-digits and more than one decimal point

  3. 3

    Storing more than one value into Isolated Storage

  4. 4

    Subsetting rows selecting on more than one value

  5. 5

    Replace strings with more than one character

  6. 6

    More than one value in rel and access using javascript or jquery

  7. 7

    Pandas: Apply(): Return more than one value

  8. 8

    Return more than one value from a function

  9. 9

    More than one maximum value in SQL

  10. 10

    Submit more than one value to database

  11. 11

    Replacing more than one elements with replace function

  12. 12

    Selecting more than one value without checkboxes

  13. 13

    JavaScript: Arguments with more than one value

  14. 14

    Pivot / crosstab with more than one value column

  15. 15

    More than one value returned by subquery

  16. 16

    replace more than one pattern python

  17. 17

    Javascript incrementing by more than one

  18. 18

    How to remove more than one whitespace from a string in javascript(Can not use regex replace function)?

  19. 19

    VLOOKUP more than one value

  20. 20

    get check box value with javascript and add those values in a div as i select more than one value

  21. 21

    Replace strings with more than one character

  22. 22

    More than one value in rel and access using javascript or jquery

  23. 23

    Javascript regex : replace more than one forward slashes with only one slash

  24. 24

    replace more than one special character with sed

  25. 25

    Replacing more than one elements with replace function

  26. 26

    Selecting more than one value

  27. 27

    Javascript incrementing by more than one

  28. 28

    How to replace more than one fragments with another one in the back stack?

  29. 29

    JAVASCRIPT How to get More than one value in Select Option

HotTag

Archive