Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Click Text, enter it in textbox

    Hey there

    Im looking to have a list of text/links, where once clicked are entered into a text box on the same page... and when a second is clicked - it is appended onto the text that is already in the text box - and so on...

    Anyone have any ideas??

    Thank youuuuu!
    briain

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Here you are:-

    Code:
    <div id = "mydiv1" onclick = "add(this)">The first text</div><br>
    <div id = "mydiv2" onclick = "add(this)">The second text</div><br>
    <div id = "mydiv3" onclick = "add(this)">The third text</div><br>
    <br><br>
    <input type = "text" id = "result" size = "60" readonly = "readonly">
    
    <script type = "text/javascript">
    function add(which) {
    var val = which.innerHTML;
    val = val + " ";  // append space as delimiter
    document.getElementById("result").value += val;
    }
    </script>

    As I prepare this script, tapping away at the keyboard as Socrates might have done had he owned a PC ....... - Football writer
    Last edited by Philip M; 06-17-2009 at 04:28 PM. Reason: Repaired missing </script> tag

  • Users who have thanked Philip M for this post:

    briain (06-17-2009)

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks Philip, this is a real help.

    Unfortunately I cant seem to get it to work

    Should I be doing more than simply putting the script in the header and the rest in the body?

    Thanks again
    briain

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Stupidly I left off the closing </script> tag.

    I have now repaired this in the post.

  • Users who have thanked Philip M for this post:

    briain (06-17-2009)

  • #5
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Perfect!

    ...the only difference is the </script> missing


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •