PDA

View Full Version : "Type your comment here" question.


Tom K
07-06-2008, 04:47 AM
On my photoblog www.tomkaszuba.com When someone wants to make a comment they have to remove the words "Type your comment here." from the comment box or they will appear in the comment. I have seen many other photoblogs with the same comment box as mine......but......the second someone clicks in the box to make a comment, the words "Type your comment here." disappear........as they should.

How can I get my comment box to work that way?

kevincrafts
07-06-2008, 05:57 AM
This javascript function will only clear it on the first click:

function clearBox(box) {
if(box.value==box.defaultValue) {
box.value = "";
}
}

and this is what the textarea tag looks like:

<textarea name='message' rows='4' cols='40' onfocus="clearBox(this);" id="message">Type your comment here.</textarea>

Tom K
07-06-2008, 06:28 AM
Thank you Kevin. It appears as though this script is already in my comment template.....yet......on one click nothing happens. The "Type your comment here" remains.

Any other ideas?

kevincrafts
07-06-2008, 04:32 PM
I am not seeing that function anywhere on your page, so there is a javascript error when the textarea is focused.

Tom K
07-07-2008, 01:02 AM
I am not seeing that function anywhere on your page, so there is a javascript error when the textarea is focused.

What can I do to correct that?

This is in my comment_template.html

<!-- SCRIPTS -->
<script language="javascript" type="text/javascript">
<!--
function clearBox(box) {
if(box.value==box.defaultValue) {
box.value = "";
}
}
//-->
</script>

and this too:

<textarea name='message' rows='2' cols='40' onfocus="clearBox(this);">Type your comment here.</textarea>

kevincrafts
07-07-2008, 03:37 AM
Your site doesn't use comment_template.html - you need that function on image_template.html

Tom K
07-07-2008, 03:58 AM
Fantastic Kevin. I added the script to the image_templaye.html and it worked perfectly. Thank you very much!

TheMarco
07-07-2008, 11:36 AM
Not that many people care these days (unfortunately) but this is bad practice. This kind of functionality should be done in JS completely in order to prevent ugly inline JS (onfocus="") and more important: to prevent non-JS users from having to delete the "Type your comment here" text manually which is royally annoying.

Unobtrusive Javascript (http://en.wikipedia.org/wiki/Unobtrusive_JavaScript)