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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts

    jquery: textarea - 'Write a comment...' and 'What's on your mind?' like facebook

    Hi,

    I would like to know how to make a textarea like the ones in facebook, which they always have default text 'Write a comment...' or 'What's on your mind?' - they will disappear when u click on the textarea, but they will change back to default when u click outside the textarea again...

    hope you understand i am trying to explain above.

    any online references please...?

    many thanks,
    Lau

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,316
    Thanks
    203
    Thanked 2,565 Times in 2,543 Posts
    It does not seem to make much sense to revert to the default text as soon as the user clicks elsewhere in the document.


    Code:
    <textarea id = "txt1" rows = "6" cols = "25" onclick = "erase()">Write a comment......</textarea>
    
    <script type = "text/javascript">
    var flag = true;
    function erase() {
    if (flag) {
    document.getElementById("txt1").value = "";
    flag = false;
    }
    }
    </script>

    Quizmaster: What "R" was Hilary Clinton's maiden name?
    Contestant: Er, um . .. is it Rottweiler?


  •  

    Posting Permissions

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