textbox form validation

Javascript coding ..

Moderators: macek, egami, gesf

whitemoss
New php-forum User
New php-forum User
Posts: 55
Joined: Thu Apr 14, 2005 1:28 am
Location: Malaysia
Contact:

textbox form validation

Postby whitemoss » Tue Dec 06, 2005 8:56 pm

Hi All,

I just need a simple help here coz I’m noon in javascript . I don’t find any of this problem in this forums so I make this thread...
How to limit our textbox to max number like 0-20,000? I’ve search but still cannot find the solution...
Please help.

Thanks.

User avatar
Shiv
php-forum Active User
php-forum Active User
Posts: 262
Joined: Wed Feb 02, 2005 8:06 pm
Location: Ahmedabad (Gujarat), INDIA

Postby Shiv » Tue Dec 06, 2005 9:17 pm

if you just want to restrict user by inputting larger value than you want then use

<input type="text" maxlength="255">

whitemoss
New php-forum User
New php-forum User
Posts: 55
Joined: Thu Apr 14, 2005 1:28 am
Location: Malaysia
Contact:

Postby whitemoss » Tue Dec 06, 2005 11:10 pm

Hi there,

Sorry for not explain you clearly but I need to make user insert the number exact 0-20000 in text not the number of digit that can be insert. The maxlength function just limits the max digit to be inserted to the textbox. Tq anyway

makarakao
New php-forum User
New php-forum User
Posts: 51
Joined: Wed Aug 24, 2005 2:10 am
Contact:

Postby makarakao » Wed Dec 07, 2005 12:23 am

Hi there!

I have used this code for my website, and it works just fine, but I don't know if it meets your requirement or not.

Here is the code

Code: Select all

<html>
<head>
<title>Limit Number</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
< script >
function setmaxnumber(txtnumber,minnumber,maxnumber){
   if(!parseFloat(txtnumber.value)){
      txtnumber.value = "";
   }
   else if(parseFloat(txtnumber.value)<minnumber){
      txtnumber.value = ""+minnumber+"";
   }
   else if(parseFloat(txtnumber.value)>maxnumber){
      txtnumber.value = ""+maxnumber+"";
   }
}
</ script >
</head>
<body>
<form action="limitnumber.php" method="post">
   <input type="text" name="txtinput" id="txtinput" maxlength="20" onKeyDown="setmaxnumber(this,0,20000);" onKeyUp="setmaxnumber(this,0,20000);" />
</form>
</body>
</html>


Makara Kao

whitemoss
New php-forum User
New php-forum User
Posts: 55
Joined: Thu Apr 14, 2005 1:28 am
Location: Malaysia
Contact:

Postby whitemoss » Wed Dec 07, 2005 12:42 am

I’ve tested it and it’s worked!! Tq Makara Kao. I owe u..

makarakao
New php-forum User
New php-forum User
Posts: 51
Joined: Wed Aug 24, 2005 2:10 am
Contact:

Postby makarakao » Wed Dec 07, 2005 1:31 am

You're welcome. :D


Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 1 guest