Forum Moderators: open

Message Too Old, No Replies

<textarea> questions

         

LABachlr

7:50 pm on Sep 26, 2003 (gmt 0)

10+ Year Member



How do I make it so that when someone clicks in the textarea box, the text that I have prewritten in there goes away? I have seen this on other sites, but not sure if it was coded with HTML.

Also, what attribute do I use to limit the number of characters that can be typed into the textarea box? And can I have a little box next to it that counts down the characters like the Cingular text message site?

korkus2000

7:55 pm on Sep 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This will clear the textarea.

<textarea name="textareaNamew" onfocus="document.formName.textareaName.value='';">Test</textarea>

The count down and character restriction is a lot more js code. I suggest you go to the site and see how they did it.

LABachlr

8:24 pm on Sep 26, 2003 (gmt 0)

10+ Year Member



Thanks, but I have other attributes in there as well. I also have questions about some of the coding.

Here are my values that correlate with the values that are in your suggested code:

document = not sure (do I just leave this as is?)
formName = Custom Quote (does it matter if there is a space?)
textareaName = Special Instructions (Again, space OK?)
value='' = Do I put a value there? If so, what?

I tried coding it exactly as you coded it, and also as I did below, and neither work:

<textarea cols="50" rows="5" maxlength="125" wrap="physical" onfocus="document.Custom Quote.Special Instructions.value='';">Type any Special Instructions here including exact quantities of any items for which you selected 10+ or 15+</textarea>

Also, do you know how to limit the amount of characters that one can type in the textarea box? maxlength="150" did not work.

Filipe

8:29 pm on Sep 26, 2003 (gmt 0)

10+ Year Member



Even easier, you don't have to change anything:

<textarea name="fieldname" OnFocus="this.value='';">Your Text Goes Here</textarea>

LABachlr

8:33 pm on Sep 26, 2003 (gmt 0)

10+ Year Member



Great. Do I change anything in the following code to correlate to my values, or leave it as is?

OnFocus="this.value='';">

LABachlr

8:36 pm on Sep 26, 2003 (gmt 0)

10+ Year Member



Also, should there be 4 sets of quotes, or just three? With only three sets of quotes, the close tag does not close the attribute.

garann

9:43 pm on Sep 26, 2003 (gmt 0)

10+ Year Member



should there be 4 sets of quotes, or just three?

I believe the middle quote is actually two single quotes/apostrophes.

BTW, I don't think it's legal to have spaces in name or id attributes - I know the validator has screamed at me before for having them in ids, at least.

LABachlr

9:46 pm on Sep 26, 2003 (gmt 0)

10+ Year Member



I decided to put the text above the text box. And just in case anyone wants to know, I found the following script that limits and counts down the amount of characters in a textarea box:

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}
// End -->
</script>

<!-- textCounter() parameters are: text field, the count field, max length -->

<form name="myform" method="post" action="">
<font size="1" face="arial, helvetica, sans-serif"> ( You may enter up to 125 characters. )<br>
<textarea name=message wrap=physical cols=28 rows=4 onKeyDown="textCounter(this.form.message,this.form.remLen,125);" onKeyUp="textCounter(this.form.message,this.form.remLen,125);"></textarea>
<br>
<input readonly type=text name=remLen size=3 maxlength=3 value="125"> characters left</font>
</form>

LABachlr

9:47 pm on Sep 26, 2003 (gmt 0)

10+ Year Member



I believe the middle quote is actually two single quotes/apostrophes.

BTW, I don't think it's legal to have spaces in name or id attributes - I know the validator has screamed at me before for having them in ids, at least.

Thanks for the info.

LABachlr

10:14 pm on Sep 26, 2003 (gmt 0)

10+ Year Member



You're absolutely right, garann.

OnFocus="this.value='';"

worked perfectly with single quotes in the middle. Didn't have to change anything. Left it as is.

Thanks, guys.