473,659 Members | 3,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script to validate all form fields for null in one quick call

6 New Member
Hello all,

I am very new to coding and even newer to Javascript. My brain works by thinking in general/abstract all the time and I am lazy, so I hate doing anything remotely repetitious. In that vein, I wrote this script to chuck through a form, any form and check for nulls where there shouldn't be. I used alerts to notify, but you could just as easily add a red error tag and focus() back. All you have to do is add informative and readable titles to fields you want null-validated. And add this to your onsubmit="retur n validation();" line. All hidden or button or submit, etc. inputs are ignored if you don't add a title to them.

Expand|Select|Wrap|Line Numbers
  1. function nullValidation() {
  2.     var x = document.getElementById("myForm");
  3.  
  4.     for (var i = 0; i < x.length; i++) {
  5.         if(x.elements[i].value == "" && x.elements[i].title) {
  6.             alert("Please enter or select " + x.elements[i].title + ".");
  7.             x.elements[i].focus();
  8.             return false;
  9.         }
  10.     }
  11.  
  12.     return true;
  13. }
  14.  
again, i am not a coder, but this simple script has saved me much, much time on new site i am building with about 20 different forms on it for getting/updating data to mysql.

regards,
oh4real
Jun 22 '07 #1
4 11784
acoder
16,027 Recognized Expert Moderator MVP
Thanks for sharing!

I've moved this to the Articles section, since it's not a problem, but a solution.

I've added code tags for you (makes it much easier to read).
Jun 22 '07 #2
letmeknow
6 New Member
thanks it really saves a lot of time in formvalidation.
Thank you
Oct 3 '07 #3
FullyH3ktik
52 New Member
Yes, thanks for sharing, it does save a lot of time compared to what I had
Oct 5 '07 #4
oh4real
6 New Member
Glad to help! I am King of generic.

Here was another time saver for PHP/MySQL:

If you ever get form submission which needs to update multiple fields in multiple tables like in a user profile, use this script that finds any fields that have changed, and then rips through to MySQL and UPDATES only those fields. I wrote this to go one field at a time, no compound UPDATE statements, since the hassle of gathering all fields from one table would cut down on SQL queries, but got complex on PHP side.

I use this PHP as an object method (one in account.class.p hp and one in user.class.php) , so admins, users, FBI, NSA, anyone who wants to can use it.

http://www.thescripts.com/forum/thread666660.html

oh4real
Oct 5 '07 #5

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

Similar topics

10
3090
by: Don | last post by:
I want the server-side php script to return a browser page that is essentially a copy of the original client page that contained the <form> which referenced the php script in the first place. However, the php script will need to change a couple html lines in that returned page. I sure could you some help on how to go about this. Thanks in advance, Don ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
6
3773
by: Andrew V. Romero | last post by:
First off, I am mostly familier with PHP but am trying to make a multi-step javascript program. For an example, I would like to run different sections of the script depending on how many times the user presses the submit button: <form method="post" name="step1" action="test.html"> <script language="JavaScript"> var position
5
4697
by: Mike | last post by:
I'm using a script provided by e-mailanywhere, it's a little too big for me. There's 1 text field and 1 password field in a form. OnSubmit, I would like both fields to be validated to look for invalid digits (~`!#$%^&*()+=?/). This is not working yet, I don't know why. In addition, I would like both fields to require from 1 to 12 digits for submition to continue. The text field also Lowers Case, can you tell me how to do the same on...
7
7607
by: Dr. Know | last post by:
I am working on an ASP page that writes to several databases, ranging from MDBs to x-base. One of the tasks involves using an existing highest value from the DB and incrementing it before inserting a new record. I am using Application.Lock and .Unlock together with an application variable to negotiate access to the DB routine to one session (user) at a time. This is to ensure that the ID numbers are cleanly incremented, and that no...
11
18830
by: Jozef | last post by:
I have some old code that I use from the Access 95 Developers handbook. The code works very well, with the exception that it doesn't seem to recognize wide screens, and sizes tab controls so that they are too big and wind up covering up some of the fields on the main form. Is there any good code out there that works in a similar fashion that will also either a) stretch the form width wise on widescreens or b), rely on height rather than...
9
6657
by: B-Dog | last post by:
I have a form that has about 10 text boxes on it, they all have to be filled out before submitting is there a quick way to make sure that none are null or do I have to call out each textbox? Say something like textbox1 through textbox10? Thanks
1
1512
by: Rollie72 | last post by:
Hello, This is a first time post for me. Have this HTML form being validated by a javascript. I am having a problem with the line "document.ACLinfo.BUmanager.value=manager;" . When in Firefox this line executes correctly , the BUmanager field is updated and the information is passed to the cgi script. When in IE it appears not to execute properly, the resulting cgi script still contains the default value and was not overwritten with...
5
2561
nathj
by: nathj | last post by:
Hi, I have been looking around the forum and the web for a way to achieve this and so far I have drawn a blank. So I head to the forum as I'm sure someone knows how to do this. I have a form which I validate as the user enters data, this is straight forward enough. Part of the validation ensures that all mandatory fields are entered before the continue button is enabled. (unfortunately this is a development site at present and so I can't...
1
47445
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
8337
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
8748
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
8531
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
8628
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...
0
7359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
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
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.