www.webdeveloper.com
Results 1 to 3 of 3

Thread: Copy one to another textbox and change letters

Hybrid View

  1. #1
    Join Date
    Sep 2012
    Posts
    1

    Copy one to another textbox and change letters

    Im using this script to copy from one to another textbox. I dont know how to make when i write in box A that what will be copied in box B to be changed. exp. Letter A ti be 001, letter E to be 002, letter V to be 008. I dont care if its in php or JavaScript.

    Thanks for your time and help

    Code:
    <html>
    <head>
    <script type="text/javascript">
        function copy_data(val){
         var a = document.getElementById(val.id).value
         document.getElementById("copy_to").value=a
        }
    
        </script>
    </head>
    <body>
    From:<input type="text" name ="a" id="copy_from" onkeyup="copy_data(this)"/><br>
    To:<input type="text" name ="b" id="copy_to"/><br>
    </body>
    </html>

  2. #2
    Join Date
    Nov 2010
    Posts
    1,036
    I can't see the logic in the substitution, so I guess you would have to build your own object. If you want it with the leading zeroes...

    Code:
    <script type="text/javascript">
        function copy_data(val){
    	var subs={"a":"001","e":"002","v":"008"}
         var b = val[val.length-1];
         document.getElementById("copy_to").value+=subs[b]
        }
    
        </script>
    </head>
    <body>
    From:<input type="text" name ="a" id="copy_from" onkeyup="copy_data(this.value)"/><br>
    To:<input type="text" name ="b" id="copy_to"/><br>
    </body>
    although you would want to have some sort of backup plan for what happens if somebody enters something that isn't one of those letters
    Last edited by xelawho; 09-20-2012 at 03:49 PM.

  3. #3
    Join Date
    Nov 2010
    Posts
    1,036
    just noticed that IE<9 doesn't like that. Better would be this:

    Code:
    <body>
    <script type="text/javascript">
        function copy_data(val){
    	var subs={"a":"001","e":"002","v":"008"}
         var b = val.charAt(val.length-1);
         document.getElementById("copy_to").value+=subs[b]
        }
    
        </script>
    From:<input type="text" name ="a" id="copy_from" onkeyup="copy_data(this.value)"/><br>
    To:<input type="text" name ="b" id="copy_to"/><br>
    </body>
    </html>

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