473,657 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple Form Validation Help

2 New Member
This is simple, SO simple but I dont know how to do it!!

I have 5 text boxes on one page (all contain numbers).

The 5th box is the sum of the first four.

I need to validate it so that the the value of the first 4 text boxes is either "0" or greater than 40

- the default of these is "0" so I thought a validation onChange() would help here??

....and the fifth box (the total) needs to always be greater than "120"

Please help, I just can't get my head around it!!

Thank you
Apr 6 '07 #1
2 1399
AricC
1,892 Recognized Expert Top Contributor
This is simple, SO simple but I dont know how to do it!!

I have 5 text boxes on one page (all contain numbers).

The 5th box is the sum of the first four.

I need to validate it so that the the value of the first 4 text boxes is either "0" or greater than 40

- the default of these is "0" so I thought a validation onChange() would help here??

....and the fifth box (the total) needs to always be greater than "120"

Please help, I just can't get my head around it!!

Thank you
What code do you have thus far?
Apr 6 '07 #2
DutchKingCobra
37 New Member
Hi pal

it would help if u posted a bit of your code!!!
but maybe this helps

EXAMPLE
Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <!-- Created on: 7-4-2007 -->
  4. <head>
  5.   <title></title>
  6.   <meta name="author" content="DutchKingCobra@live.nl">
  7. <script language="JavaScript1.2" >
  8. function Validate(){ 
  9.  
  10. if (Form1.textbox1.value == ''){alert('textbox1 is empty');return false;}
  11. else if (Form1.textbox1.value == 0 || Form1.textbox1.value > 40){alert('Please enter a number between 0 and 41');return (false);}
  12.  
  13. if (Form1.textbox2.value == ''){alert('textbox2 is empty');return false;}
  14. else if (Form1.textbox2.value == 0 || Form1.textbox2.value > 40){alert('Please enter a number between 0 and 41');return (false);}
  15.  
  16. if (Form1.textbox3.value == ''){alert('textbox3 is empty');return false;}
  17. else if (Form1.textbox3.value == 0 || Form1.textbox3.value > 40){alert('Please enter a number between 0 and 41');return (false);}
  18.  
  19. if (Form1.textbox4.value == ''){alert('textbox4 is empty');return false;}
  20. else if (Form1.textbox4.value == 0 || Form1.textbox4.value > 40){alert('Please enter a number between 0 and 41');return (false);}
  21.  
  22. if (Form1.textbox5.value == ''){alert('textbox5 is empty');return false;}
  23. else if (Form1.textbox5.value == 0 || Form1.textbox5.value < 120){alert('minimum 120');return (false);}
  24.  
  25. else {return (true);}
  26. }
  27. </script>
  28. </head>
  29. <body>
  30. <form name="Form1" action="" onsubmit="Validate()">
  31. <input type="text" name="textbox1" size="40" value="enter a value between 0 and 41" maxlength="256"><br>
  32. <input type="text" name="textbox2" size="40" value="enter a value between 0 and 41" maxlength="256"><br>
  33. <input type="text" name="textbox3" size="40" value="enter a value between 0 and 41" maxlength="256"><br>
  34. <input type="text" name="textbox4" size="40" value="enter a value between 0 and 41" maxlength="256"><br>
  35. <input type="text" name="textbox5" size="40" value="total" maxlength="256"><br>
  36. <input type="submit" value="submit">
  37.  
  38. </form>
  39. </body>
  40. </html>
  41.  
  42.  
Apr 7 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
2966
by: r0adhog | last post by:
I have a very simple form: <html> <head> </head> <body> <% function ValForm() if len(document.form.newapp.all("AccessCode").Value) = 4 then document.form.newapp.submit()
6
4336
by: Charles Banas | last post by:
weird subject - i hope more than just one curious regular will hear me out. :) ok, i've got a bit of a big problem, and i need answers as soon as possible. i know this forum is meant for web developers, but is relevant discussion. i'm not OT here unless someone thinks i'm trolling (which i'm not, obviously). then i'll disappear and never show my face again. :P
4
2630
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a script that validates the form fields. the validation procedure is called ONCLICK event of the submit button. Follwowing is the structure of the validation procedure.
3
1639
by: Marc Llenas | last post by:
Hi there, I'm stuck on a validation function for a form and I cannot figure out what the problem is. The page is in ASP. Any ideas? The function being called is: <script language="JavaScript" type="text/javascript"> function checkform ( form ) {
2
8387
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the client side javacript code for form validation and client side editing capabilities in order to save...
18
3026
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How ??
9
4167
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation (e.g. this is numeric, this is alpha-numeric, etc.)
5
3215
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The javascript method will do the form validation for each field one by one. For each field, an XMLHttpRequst will be made to a PHP file and get the return, either set an error field (<span>'s innerHTML) or leave it empty. Then I'll check the error field...
1
1235
by: Bambers | last post by:
hi all i have an contact us form with validation. the submit button make the script re-run and do the validation. the problem i have is; when all the validation is done and the user input is correct, how do i make the brouser go to the next page. i need it to pass vaiables into contact.php which sends the email i cannot understand how to do it becuase the only form action i have is one that recalls itself. any help would be great
0
8315
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.