Advanced Search

Results 1 to 2 of 2

Thread: Putting textbox text into variable

  1. #1
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Putting textbox text into variable

    How do I get the text from a textbox into a variable?

    I am trying to make it so onclick text from one textbox is put into another:

    Code:
    <script type="text/javascript">
    var test= ???
    function movetext(){
        document.getElementById("text2").value=test;
    }
    </script>
    
    <a onclick="movetext(); return false;">Click</a>
    
    <input type="text" id="text1"><br><br>
    <input type="text" id="text2">
    Thanks for your help

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,704
    Thanks
    43
    Thanked 3,133 Times in 3,097 Posts
    Blog Entries
    12

    Default

    To copy:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript">
    function movetext(){
        document.getElementById("text2").value = document.getElementById("text1").value;
    }
    </script>
    
    </head>
    <body>
    <a href="#" onclick="movetext(); return false;">Click</a>
    
    <input type="text" id="text1"><br><br>
    <input type="text" id="text2">
    
    </body>
    </html>
    To move:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript">
    function movetext(){
        document.getElementById("text2").value = document.getElementById("text1").value;
        document.getElementById("text1").value = ''
    }
    </script>
    
    </head>
    <body>
    <a href="#" onclick="movetext(); return false;">Click</a>
    
    <input type="text" id="text1"><br><br>
    <input type="text" id="text2">
    
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Replies: 2
    Last Post: 12-30-2011, 01:27 AM
  2. Putting Slideshow Text in the Middle
    By JohnWillbs in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 04-19-2011, 03:46 AM
  3. Replies: 2
    Last Post: 09-08-2006, 09:20 PM
  4. Replies: 2
    Last Post: 09-07-2006, 04:34 PM
  5. Putting extra text around links
    By Shattered Plastic in forum CSS
    Replies: 2
    Last Post: 09-10-2004, 08:22 PM

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
  •