Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DIsplaying a textbox when clicks a link 1

Status
Not open for further replies.

ag1060

Programmer
Aug 26, 2011
27
US
Hello,

I'm pretty new to JS and I have this HTML form that has hidden values and I want to display a text click that states, "Post Comments" and the following should display:

Code:
<form  name="comment_box" method="post" action="/project/post_comments">
  <textarea name="comments" class="pseudo-multiline" autocomplete="off" style="width:100%;height:22px;"></textarea>
  <input type="hidden" name="pid" value="$pid">
  <input type="hidden" name="post_id" value="$post_id">
    <input type="hidden" name="uid" value="$uid"><br>
	<input type="submit" value="Post Comments" class="submit">
</form>

any idea on how to start? Thanks for any help in advance.
 
I'd start bu hidding the form:

Code:
<form  name="comment_box" method="post" action="/project/post_comments" style="display:none;">

Then simply change the display property onclick:

Code:
<a href="#" onclick="document.forms.comment_box.style.display='block'; return false;">Show Comment Form</a>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Thank you. That was pretty simple than I thought. One small question, what if I want to change 'Post Comments' to 'Hide Box' without adding an additional text? So far, I just add 'Close Button' at the end of the comment box:

Code:
[<a href="#" onclick="document.forms.comment_box_$post_id.style.display='none'; return false;">Close</a>]

But obviously that 'Post Comments' still stays on; any way I can just change that 'Post Comments' to 'Hide Box' without adding additional text at the end?

Thanks in advance.
 
Not sure I understand, but you if what you want is to replace the "Post Comments" string with the "Hide Box" string you'll have to perform some checks.


Code:
[COLOR=#990000]<[/color]a href[COLOR=#990000]=[/color][COLOR=#FF0000]"#"[/color] onclick[COLOR=#990000]=[/color][COLOR=#FF0000]"if(document.forms.comment_box.style.display=='' || document.forms.comment_box.style.display=='none'){document.forms.comment_box.style.display='block'; this.innerHTML = 'Hide Box';}else{document.forms.comment_box.style.display='none' this.innerHTML = 'Show Comment';} return false;"[/color][COLOR=#990000]>[/color]Show Comment Form[COLOR=#990000]</[/color]a[COLOR=#990000]>[/color]

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Thanks for the code; it works great. I was looking for that :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top