plik-u

Articles, Tips & Tricks, Usefull Softwares

Menghitung Sisa Huruf / Karakter pada Textarea

Ingin mengetahui berapa huruf lagi yang dapat Anda ketikkan di Textarea? maka gunakanlah script dibawah ini.

<form name=”myForm”
action=”/articles/articles/javascript/dynamictextareacounter.asp?ID=<%=siteID%>”
method=”post”>
<b>One Function to Count and Limit Multiple Form Text Areas</b><br>
<textarea name=”message1″ wrap=”physical” cols=”28″ rows=”5″
onKeyDown=”textCounter(document.myForm.message1,document.myForm.remLen1,125)”
onKeyUp=”textCounter(document.myForm.message1,document.myForm.remLen1,125)”></textarea>
<br>
<input readonly type=”text” name=”remLen1″ size=”3″ maxlength=”3″ value=”125″>
characters left
<br>
<textarea name=”message2″ wrap=”physical” cols=”28″ rows=”5″
onKeyDown=”textCounter(document.myForm.message2,document.myForm.remLen2,125)”
onKeyUp=”textCounter(document.myForm.message2,document.myForm.remLen2,125)”></textarea>
<br>
<input readonly type=”text” name=”remLen2″ size=”3″ maxlength=”3″ value=”125″>
characters left
<br>
<input type=”Submit” name=”Submit” value=”Submit”>
<br>
</form>

Dan letakkan script di bawah ini di bagian <HEAD>….</HEAD> website Anda.

<SCRIPT LANGUAGE=”JavaScript”>
<!– Dynamic Version by: Nannette Thacker –>
<!– http://www.shiningstar.net –>
<!– Original by :  Ronnie T. Moore –>
<!– Web Site:  The JavaScript Source –>
<!– Use one function for multiple text areas on a page –>
<!– Limit the number of characters per textarea –>
<!– Begin
function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long…trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update ‘characters left’ counter
else
cntfield.value = maxlimit – field.value.length;
}
//  End –>
</script> 

Ok, silahkan mencoba..

Advertisements

December 15, 2008 - Posted by | Programming | , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: