Current location: Hot Scripts Forums » General Web Coding » JavaScript » Make button appear


Make button appear

Reply
  #1 (permalink)  
Old 11-13-07, 03:59 PM
staticfire's Avatar
staticfire staticfire is offline
Wannabe Coder
 
Join Date: May 2007
Location: Stockton, England
Posts: 223
Thanks: 0
Thanked 1 Time in 1 Post
Make button appear

Hello all,

I just recently started learning Javascript to improve my web coding ability and i am currently studying form validation. I set this up so that the submit button only shows when the user has entered more than 200 characters. This script does not appear to be working

Code:
<script type="text/javascript">

 if (comment_form.comment.value.length > 200){

     document.write("<center><input type='submit' name='send' value='Send Comment'></center>");

}

</script>
Any help would be appreciated, Thank you.
__________________
Visit http://www.staticfire.co.uk

Last edited by staticfire; 11-13-07 at 04:01 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-13-07, 04:37 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
You may need to call your code on each onKeyUp() event so it checks comment_form.comment.value.length. Otherwise the code you've shown will only be called once (when the page is first opened). This will work:

Code:
<form name="comment_form">
<textarea name="comment" id="comment" onkeyup="checkCommentLength()"></textarea>
<center><input type='submit' name='send' value='Send Comment' ></center>
</form>
<script language="javascript">
     comment_form.send.style.visibility="hidden";

function checkCommentLength(){

  if (comment_form.comment.value.length > 5){
     comment_form.send.style.visibility="visible";
  }else{
     comment_form.send.style.visibility="hidden";
  }
}
</script>
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]

Last edited by End User; 11-13-07 at 04:47 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-13-07, 04:44 PM
staticfire's Avatar
staticfire staticfire is offline
Wannabe Coder
 
Join Date: May 2007
Location: Stockton, England
Posts: 223
Thanks: 0
Thanked 1 Time in 1 Post
So i should perhaps make a function and call it in the keyup event of the textarea?
__________________
Visit http://www.staticfire.co.uk
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-13-07, 04:47 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
See the code I pasted in above...it should work.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 11-13-07, 05:15 PM
staticfire's Avatar
staticfire staticfire is offline
Wannabe Coder
 
Join Date: May 2007
Location: Stockton, England
Posts: 223
Thanks: 0
Thanked 1 Time in 1 Post
Ok i just implemented that into my site and it's working fine. Thanks a lot
__________________
Visit http://www.staticfire.co.uk
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 11-16-07, 04:09 AM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
just as a side note the above code may have problems running in FF or produce and error...

you should try using:

getElementById('send')

Code:
<form name="comment_form">
<textarea name="comment" id="comment" onkeyup="checkCommentLength()"></textarea>
<center><input type='submit' id='send' value='Send Comment' ></center>
</form>
<script language="javascript">
     comment_form.getElementById('send').style.visibility="hidden";

function checkCommentLength(){

  if (comment_form.comment.value.length > 5){
     comment_form.getElementById('send').style.visibility="visible";
  }else{
     comment_form.getElementById('send').style.visibility="hidden";
  }
}
</script>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 11-25-07, 04:40 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by scott2500uk View Post
just as a side note the above code may have problems running in FF or produce and error...
What version of FF? The only browser I normally use is FF and it worked fine here.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make button more attractive mathfxr HTML/XHTML/XML 1 01-12-06 05:29 PM


All times are GMT -5. The time now is 06:44 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.