ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 14th, 2002, 09:25 AM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 7
Send a message via MSN to aspnewbie
Question Requiring User to Enter Number Which is a Certain Interval

Hi All,

I've created a asp form which requires the user to enter a number. I'm wondering if there is a way to check to ensure that the number entered is of a certain interval (say 5s) and return an error message if it doesn't meet that criteria. I would prefer to do this with javascript to avoid a trip to the server.

As javascript isn't my strong point, any assistance would be greatly appreciated!

Reply With Quote
  #2  
Old October 14th, 2002, 10:50 AM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 7
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
this function should do the trick

just change the maxNumber and minNumber to the interval you would like


Code:
function checkform(oForm)
{
var maxNumber = 5;
var minNumber = 1;

formNumber = oForm.testnumber.value;
if (isNaN(formNumber))
{
  alert("formnumber is not numeric");
  return false;
}

if ( formNumber - maxNumber > 0)
{
  alert("wrong number");
  return false;
}

if ( formNumber - minNumber < 0)	
 {
  alert("wrong number");
  return false;
}
}


Call the script by <. form action="your action page" method="post" name="theForm" onSubmit="javascript: return checkForm(this)">
__________________
- Rogier Doekes

Last edited by rdoekes : October 14th, 2002 at 10:54 AM.

Reply With Quote
  #3  
Old October 14th, 2002, 12:09 PM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 7
Send a message via MSN to aspnewbie
Thanks a lot for the quick and detailed response! I'm a little unclear as to whether it will actually do what I want, though.

Just to give you a little more of an explanation, I need the users to enter bids in $5 denominations (it's for a online charity auction). If someone types in $31 they should get an error, but if they type in $30, then the form should submit.

With your function, if the max number is 5, then wouldn't either 30 or 31 return false because they would be greater than zero?

Last edited by aspnewbie : October 14th, 2002 at 12:23 PM.

Reply With Quote
  #4  
Old October 20th, 2002, 12:25 PM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 7
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
modulus 5

Ok, I think the trick is to use the integer division function modulus in javascript (%)
Code:
function checkform(oForm)
{
 var intervalNumber = 5;


 formNumber = oForm.testnumber.value;

 if (isNaN(formNumber))
 {
  alert("formnumber is not numeric");
  return false;
 }

 if ( formNumber % intervalNumber > 0)
 {
  alert("wrong number");
  return false;
 }

}


hope this helps

Reply With Quote
  #5  
Old October 20th, 2002, 09:43 PM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 7
Send a message via MSN to aspnewbie
Smile

Awesome. This looks great. It shows that I should really learn more javascript, given all its functionality!

Thanks again for your help!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > Requiring User to Enter Number Which is a Certain Interval


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT