Help - Search - Members - Calendar
Full Version: Checking textbox field
HTMLHelp Forums > Programming > Client-side Scripting
rrn
in my website ther is a textbox for entering year..

i have given code for displaying an alert message if the textbox is left empty..

CODE
function validate() {
if(document.form.name.value=="")
{
alert ('Please enter Name');
return false;
}}



it is working , but i want to do is..

it should display an alert message if the length of the numbers is greater than 5
ie if it is 19995 , it sholud display an alert message..
how can i do that??

please give me a solution...
thanks......
Christian J
QUOTE(rrn @ May 26 2009, 11:08 AM) *

it should display an alert message if the length of the numbers is greater than 5

You can use the "length" property on the field's value or use the MAXLENGTH attribute of INPUT text fields for counting characters. Just like with javascript you can't rely on MAXLENGTH but must double-check in the server-side script. You may also want to check that it's a number at all (google for the JS isNaN() method).

But wouldn't it be better to limit the allowed value (not character length), e.g. between 1950 and 2050? Four characters (I assume you meant "greater than 4" above?) could mean any year between 1000 and 9999, or even "1.00".
rrn
QUOTE(Christian J @ May 26 2009, 04:57 AM) *

QUOTE(rrn @ May 26 2009, 11:08 AM) *

it should display an alert message if the length of the numbers is greater than 5

You can use the "length" property on the field's value or use the MAXLENGTH attribute of INPUT text fields for counting characters. Just like with javascript you can't rely on MAXLENGTH but must double-check in the server-side script. You may also want to check that it's a number at all (google for the JS isNaN() method).

But wouldn't it be better to limit the allowed value (not character length), e.g. between 1950 and 2050? Four characters (I assume you meant "greater than 4" above?) could mean any year between 1000 and 9999, or even "1.00".



Thanks a lot for ur suggestion..
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.