www.webdeveloper.com
Results 1 to 4 of 4

Thread: Clone div text into form field

  1. #1
    Join Date
    Jun 2008
    Location
    London
    Posts
    175

    Clone div text into form field

    Hey all, I'm using a form that looks something up online when submitted and displays the results in a DIV called 'results'. I'm trying to get that content to automatically populate a form field on the same page but just can't get it to work. This works but obviously repeats every second and clones into a DIV not a form field

    HTML Code:
    <div id="results"></div>
    <div id="test"></div>
    
    <script type="text/javascript">
    window.setInterval(function(){
    $('#results').clone().appendTo('#test');
    }, 1000);
    </script>
    I guess I'm looking for something like this but its not working and not sure how I should go about cloning text to a form value

    HTML Code:
    <div id="results"></div>
    <input name="test" id="test" type="text">
    
    <script type="text/javascript">
    $(document).ready(function() {
    $('#results').delay(2000).clone().appendTo('#test');
    });
    </script>
    Any help would be really appreciated. Thanks

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,670
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>123</title>
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    </head>
    <body>
    <center>
    <div id="results"><b>S</b><span>ome</span> <i>co</i><p>nte</p><a>nt</a><br /><br /><br /></div>
    <input name="test" id="test" type="text" />
    </center>
    <script type="text/javascript">
    $(document).ready(function(){
    var txt=$('#results').text();
    setTimeout(function(){$('#test').val(txt);},2000);
    });
    </script>
    </script>
    </body>
    </html>

  3. #3
    Join Date
    Jun 2008
    Location
    London
    Posts
    175
    Awesome, that works Thanks for your help

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,670
    anytime ))

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