Jump to content

show and hide


scvinodkumar

Recommended Posts

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.

 

 

 

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.