SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Non-Member
    Join Date
    Sep 2004
    Location
    India
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Need Simple Javascript

    Hi,

    I need a simple javascript which should replace spaces with - from a form field. I don't mind if its done after clicking the submit button or after loosing focus from the field itself.

    Please help.

    Thanks.

  2. #2
    SitePoint Enthusiast Sjoerd's Avatar
    Join Date
    Jun 2005
    Location
    Leimuiden, The Netherlands
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    HTML Code:
    <input type="text" onblur="this.value = this.value.replace(' ', '-');">

  3. #3
    Non-Member
    Join Date
    Sep 2004
    Location
    India
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for the code but i still have a small problem. If i enter some text like: This is a small test then its gets converted to: This-is a small test instead of This-is-a-small-test

    Please help replace all spaces to -.

    Thanks.

  4. #4
    SitePoint Enthusiast Sjoerd's Avatar
    Join Date
    Jun 2005
    Location
    Leimuiden, The Netherlands
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops, forgot about it, try this instead:

    HTML Code:
    <input type="text" onblur="this.value = this.value.replace(/ /g, '-');">

  5. #5
    Non-Member
    Join Date
    Sep 2004
    Location
    India
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks, works like a charm. I need one more favour.
    I need javascript which would copy the text entered into the field to another field. I don't mind if it happens as the user enters text or after the text has been entered and user has moved to next field.

    So its basically. The user enters text in 1st field and as soon as he presses tab or goes or 2nd field the 2nd field should have value of 1st field. If user wants to modify it etc. then fine after that when user moves to 3rd field the spaces in 2nd field should get replaced by - whcih we have already done.

    So we just now need to copy 1st field data to 2nd field.

    Thanks.

  6. #6
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  7. #7
    Non-Member
    Join Date
    Sep 2004
    Location
    India
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks it helped.

    Thanks.


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
  •