Solved

Javascript to check for a blank form

Posted on 2009-04-05
9
182 Views
Last Modified: 2012-05-06
Hi - I have an online employment application form that I uses CGI script to send the data to my email. I do not want a blank form to get submitted. I need some simple javascript that can check to see if all fields are empty and if so not to submit the form.  A window can pop up saying something like the form has not been completed. What is the best way to achieve this? Thank you.
0
Comment
Question by:reesecup09
  • 4
  • 2
9 Comments
 
LVL 12

Expert Comment

by:basav_com
ID: 24072398
0
 

Author Comment

by:reesecup09
ID: 24072435
Is there a way to check for a completely blank form instead of an individual field?
0
 
LVL 12

Accepted Solution

by:
basav_com earned 125 total points
ID: 24072500
You can do like this:


function checkscript() {

	for (i=0;i<4;i++) {

		box = document.example.elements[i];

		if (!box.value) {

			alert('You haven\'t filled in ' + box.name + '!');

			box.focus()

			return false;

		}

	}

	return true;

}

Open in new window

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 12

Expert Comment

by:basav_com
ID: 24072508
0
 

Author Comment

by:reesecup09
ID: 24072964
Will this check to see if no field has been completed?
0
 
LVL 12

Expert Comment

by:basav_com
ID: 24073201
yes... check the tutorial for more understanding.
0
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 37169580
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now