www.webdeveloper.com
Results 1 to 12 of 12

Thread: Format input value on 'onkeyup'

Threaded View

  1. #1
    Join Date
    Oct 2008
    Posts
    7

    Format input value on 'onkeyup'

    Hello:

    Could someone help me to join the following two codes? I'm a PHP/MySQL programmer but have no experience with Javascript coding. I've tried various combinations and have read some online Javascript tutorials but I cannot figure out how to create a code to dynamically format information typed into an input field and have it transfer to another input field on 'onkeyup.'

    Here's what I have so far for copying the data from one input field to another:

    HTML Code:
    <form name="test">
        <p>First Name: <input type="text" name="Afname" onkeyup="copy()"></p>
        <p>First Name: <input type="text" name="Bfname"></p>
    </form>
    <script type="text/javascript">
    function copy()
    {
        document.test.Bfname.value = document.test.Afname.value;
    }
    </script>

    And here's what I found online to do the formatting:
    HTML Code:
    <script type="text/javascript">
    // Store the current title value
    var title = 'This is a title with a symbol &'
    	// alert(title); // debug
      	// Clean up the title		
    var url
      	.toLowerCase() // change everything to lowercase
      	.replace(/^\s+|\s+$/g, "") // trim leading and trailing spaces		
      	.replace(/[_|\s]+/g, "-") // change all spaces and underscores to a hyphen
      	.replace(/[^a-z0-9-]+/g, "") // remove all non-alphanumeric characters except the hyphen
      	.replace(/[-]+/g, "-") // replace multiple instances of the hyphen with a single instance
      	.replace(/^-+|-+$/g, ""); // trim leading and trailing hyphens
    	alert(url); // outputs 'this-is-a-title-with-a-symbol'
    </script>
    The second code is exactly what I need (see comments) but I don't know how to format the first code to work with the second one. There are scripts online that do this but only after clicking on the submit button. I don't want to click on a submit button. I want the script to work dynamically and format the input field data as I type. Can this be done?


    Can someone please help?

    Thank you!
    Last edited by JsusSalv; 10-30-2008 at 04:26 AM.

Thread Information

Users Browsing this Thread

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

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