scvinodkumar Posted June 1, 2009 Share Posted June 1, 2009 Hi, Example, <div id="1"> <a href=\"javascript:void(0);\" onclick=\"show_comments('1');\">Comments1</a> <div id="1" style="display:none;"> <textarea id="content_1"></textarea> </div> </div> <div id="2"> <a href=\"javascript:void(0);\" onclick=\"show_comments('2');\">Comments2</a> <div id="2" style="display:none;"> <textarea id="content_2"></textarea> </div> </div> ..... i have this code in my comments page, when i click the comments1 it should open the first textarea with focus,similary for comments2. And,I need to hide first comments either when the comments2 get focus or first comments1 lose focus Totally, at a time only one textarea should be display and get focus I hope you understand Waiting for your reply. Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted June 1, 2009 Share Posted June 1, 2009 you can do this using the onfocus http://www.w3schools.com/jsref/jsref_onfocus.asp and onblur http://www.w3schools.com/jsref/jsref_onblur.asp events in javascript something like this. I am not entirely sure that numeric IDs work in javascript, so I have changed them for the purpose of this example <script type="text/javascript"> function blurComment(id) { //comment lost focus so hide it document.getElementById(id).style.display = 'none'; } function clickComment(id) { if(id=='one') { document.getElementById('one').style.display = ''; document.getElementById('two').style.display = 'none'; } if(id=='two') { document.getElementById('one').style.display = 'none'; document.getElementById('two').style.display = ''; } } </script> Quote Link to comment Share on other sites More sharing options...
scvinodkumar Posted June 2, 2009 Author Share Posted June 2, 2009 Hi, Bascially i need the facebook like comments. I have attached the document with examples, please go through this. There is three links(comment1,comment2 and comment3) If you click on comment1 it will display textarea1 with focus. If the textarea1 lose focus it will hide the textarea1, only if there is no text in the textarea1. similarly for comment2 - textarea2 and comment3 - textarea3. Now the problem is, after clicking comment1, if u click on comment2 it will hide the hide the textarea1 but not displaying textarea2 I hope u understand this. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.