Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2009
    Thanked 0 Times in 0 Posts

    onkeyup copy text from one field to another


    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:
    <script type = "text/javascript">
    function transfer(which) {
    	reg = /\s+/;
    	document.getElementById("uri").value = which.toLowerCase().replace(reg,'-');
    <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?


  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,573 Times in 2,551 Posts
    function transfer(which) {
    reg = /\s+/g; // the g switch means global.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.


    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