www.webdeveloper.com
Results 1 to 3 of 3

Thread: onkeyup copy text from one field to another

Hybrid View

  1. #1
    Join Date
    Feb 2009
    Posts
    17

    onkeyup copy text from one field to another

    Hi,

    I have two text fields, 1) Page Title and 2) URI. As and when the user types in the Page Title, I want the text to be copied straight into the URI text field, but after having made all letters small and replacing ' ' (space) with '-' minus sign.

    This is what I have so far:
    Code:
    <script type = "text/javascript">
    function transfer(which) {
    	reg = /\s+/;
    
    	document.getElementById("uri").value = which.toLowerCase().replace(reg,'-');
    }
    </script>
    <input type="text" name="title" id="title" value="" size="32" onkeyup = "transfer(this.value)">
    <input type="text" name="uri" id="uri" value="" size="32">
    case lowering works fine, but with space replacement, it only replaced the first space with '-', and leaves the rest of the spaces as they are.

    Hence, this is how it looks:

    Page Title: This is my Pompous Page Title
    URI: this-is my pompous page title

    How can I get it to continue replacing all spaces and not just the first one?

    Thanks!

  2. #2
    Join Date
    Oct 2008
    Location
    U.S.
    Posts
    726
    var reg = /\s+/g; //g flag for global (within the string)

  3. #3
    Join Date
    Feb 2009
    Posts
    17
    Quote Originally Posted by astupidname View Post
    var reg = /\s+/g; //g flag for global (within the string)
    Thank you very much!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles