Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

textbox form validation

Javascript coding ..

Moderators: macek, egami, gesf

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.
whitemoss
New php-forum User
New php-forum User
 
Posts: 55
Joined: Thu Apr 14, 2005 1:28 am
Location: Malaysia

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">
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 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
whitemoss
New php-forum User
New php-forum User
 
Posts: 55
Joined: Thu Apr 14, 2005 1:28 am
Location: Malaysia

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
makarakao
New php-forum User
New php-forum User
 
Posts: 51
Joined: Wed Aug 24, 2005 2:10 am

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

I’ve tested it and it’s worked!! Tq Makara Kao. I owe u..
whitemoss
New php-forum User
New php-forum User
 
Posts: 55
Joined: Thu Apr 14, 2005 1:28 am
Location: Malaysia

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

You're welcome. :D
makarakao
New php-forum User
New php-forum User
 
Posts: 51
Joined: Wed Aug 24, 2005 2:10 am


Return to JavaScript

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.