SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery's Equiv. of str_replace

    Does jQuery have an equivalent of PHP's str_replace? I am needing to replace spaces in a text box with hyphens.

    I googled and looked in the forum search but wasn't coming up with a good answer.

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,061
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Code javascript:
    someString.replace(/\s/, "-");

    For more info see the W3C site on the replace() function.

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    To add to the above, you don't even need a regular expression:

    Code javascript:
    str.replace(' ', '-');

    Also please note that that isn't jQuery, that's JavaScript. jQuery is not a language. If you have a text box, you'll probably have to do something like this with jQuery:

    Code javascript:
    var textarea = $('#the_textarea');
    var txt = textarea.val();
    textarea.val(txt.replace(' ', '-'));


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •