Creating an HTML5 Validator (CHV)

Counting Characters in textarea

If we have ever visited a website that provides free SMS sending facilities, usually we will find a TextArea Form to fill in the SMS message that we will send. The TextArea limits the number of characters that we input. Here is the source program:

<html>
<head>
<title</title>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<script>
function CountMax()
{  var wert,max;  max = 100
wert = max-(document.form1.question.value.length);  if (wert < 0) {
alert("Maaf, batas maksimum pengisian adalah  " + max + " karakter!");  document.form1.question.value = document.form1.question.value.substring(0,max);  wert = max-(document.form1.question.value.length);  document.form1.rv_counter.value = wert;

} else {
document.form1.rv_counter.value =  max-(document.form1.question.value.length);
}
}

</script>
</head>
<body >
<form name="form1" method="post" action="">
<textarea  name="question"  cols="60"  rows="3"  id="question"  OnFocus="CountMax();" OnClick="CountMax();"  ONCHANGE="CountMax();"  onKeydown="CountMax();" onKeyup="CountMax();" wrap="virtual"></textarea>
<font face="Arial, Helvetica, sans-serif, Bookman Old Style, Comic Sans MS" size="2">sisa
<input name="rv_counter" type="TEXT" size="3" maxlength="3" value="100readonly></form> </body>
</html>

Pay attention to the TextArea properties, every time we type a character or number in the TextArea, the CountMax javascript function will always count the number of characters or numbers filled in the TextArea. Each count will automatically fill the TextBox column (rv_counter) below it. The filling is in the form of reducing the maximum keyboard input defined by the variable max = 100 by each keyboard input type that we do. When the number of keyboard inputs is equal to or greater than the variable max = 100, the alert function will be executed.

Note: works fine on IE & Modzilla browsers

Here are some Javascript Programming Tips & Tricks. All of the source programs above have been used by the author to help create a web application project as the initial processing of a form. Hopefully this article is useful for all of us. Thank you.

Library:

By:

Biography and Profile

Setiaji. Born in Jakarta, February 1978. This shy young man graduated from SMUN 65 Jakarta in 1996. Completed his undergraduate program in Computer Engineering at Budi Luhur University in 2001. Currently working at a Content Provider company in Jakarta as a programmer.

Source:

IlmuKomputer.Com

Numeric Textbox Input Validator

Often when we create a web form for an application program, only numeric (numbers) are allowed to be filled in the textbox. Here is the source program:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="">
<input name="periode" type="text" id="periode" size="15" maxlength="15" onKeypress="if
(event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;">
</form>
</body> </html>

Properties onKeyPress with the above conditions will limit the function of the keys on the keyboard to only numeric (numbers) that can be input. We can also change the conditions according to our wishes by replacing or adding codes. For the case above, the numeric (numbers) on the keyboard keys are between codes 48 to 57. ( http://rmhh.co.uk/ascii.html ).

Note: works fine on IE browser


Post a Comment

Previous Next

نموذج الاتصال