Advanced Search

Results 1 to 7 of 7

Thread: Move last X chars from one field to another

  1. #1
    Join Date
    Mar 2008
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Move last X chars from one field to another

    Hello helpful people!

    I have been browsing the forum a while and decided this place is so friendly that I will try my luck submiting my own question.

    Here goes:

    I need a javascript that can take all characters after the first X amount entered into a text field and move them to another when the user exits the field (using onblur?).

    Kudos to anybody who can help!

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    HTML Code:
    <textarea onBlur="document.getElementById('receive').value=this.value.substring(3)"></textarea>
    <textarea id="receive"></textarea>
    where 3 is the number of characters. Can work with input too, you just need the id.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. The Following User Says Thank You to Master_script_maker For This Useful Post:

    NightAvatar (03-24-2008)

  4. #3
    Join Date
    Mar 2008
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Excellent, Thanks!

    Excellent, Thanks!

    That was perfect!

    I forgot to say I needed the X characters removed from the first field as well as placed in the second field.

    Any idea how to do that?

    Thanks again for such a speedy response!

  5. #4
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    you want the characters removed in the first field and the text from the first, in the second?
    HTML Code:
    <textarea onBlur="document.getElementById('receive').value=this.value.substring(3);this.value=this.value.substring(3)"></textarea>
    <textarea id="receive"></textarea>
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  6. #5
    Join Date
    Mar 2008
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Not quite

    Thanks, but not quite like that.

    I need the text that is moved to the second field removed from the first, while the beginning of the text remains.

    For example, if I write "Hello World" in the first field, with 3 as the number to keep, then "Hel" will stay in the first, and "lo World" will be moved to the second field.

    I hope that makes it clearer.

    Kudos to whomever can help me out!

  7. #6
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    See if this code fit your heart's desire
    I'll separate the presentation (JS) from the markups (html).
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    window.onload = function()
    {
    	document.getElementById('input').onblur = function()
    	{
    	document.getElementById('receive').value=this.value.substring(3);
    	this.value=this.value.substring(0,3);
    	}
    }
    </script>
    <body>
    <textarea id="input"></textarea>
    <textarea id="receive"></textarea>
    </body>
    </html>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  8. The Following User Says Thank You to rangana For This Useful Post:

    NightAvatar (03-25-2008)

  9. #7
    Join Date
    Mar 2008
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Damn, you're good!

    That's EXACTLY what I needed.

    Thanks rangana!

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
  •