Solved

Required fields in form

Posted on 2008-10-03
6
254 Views
Last Modified: 2012-05-05
Form location- https://secure1.securewebexchange.com/fwrhomes.com/credit.htm

How do you make particular fields give a required message in a form?
0
Comment
Question by:squirtle98
  • 4
  • 2
6 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 22635764
on Submit, have the form go to a validation function...and make sure they meet your requirements...
0
 
LVL 21

Expert Comment

by:silemone
ID: 22635774
simple example...it's simple no matter how many controls you have...

http://www.elated.com/articles/form-validation-with-javascript/
0
 
LVL 21

Expert Comment

by:silemone
ID: 22635818
also if you want message to appear, show hidden divs...
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 19

Expert Comment

by:erikTsomik
ID: 22636070
you can use client side validation to do that Javascript, or sever side  i do not know what language are you using
0
 
LVL 21

Expert Comment

by:silemone
ID: 22636672
erik...look under his question and at Tags...
0
 
LVL 19

Accepted Solution

by:
erikTsomik earned 500 total points
ID: 22636727
try this .
<script language="JavaScript">
 
 

function formCheck(formobj){

	// Enter name of mandatory fields

	var fieldRequired = Array("FirstName", "LastName");

	// Enter field description to appear in the dialog box

	var fieldDescription = Array("First Name", "Last Name");

	// dialog message

	var alertMsg = "Please complete the following fields:\n";

	

	var l_Msg = alertMsg.length;

	

	for (var i = 0; i < fieldRequired.length; i++){

		var obj = formobj.elements[fieldRequired[i]];

		if (obj){

			switch(obj.type){

			case "select-one":

				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){

					alertMsg += " - " + fieldDescription[i] + "\n";

				}

				break;

			case "select-multiple":

				if (obj.selectedIndex == -1){

					alertMsg += " - " + fieldDescription[i] + "\n";

				}

				break;

			case "text":

			case "textarea":

				if (obj.value == "" || obj.value == null){

					alertMsg += " - " + fieldDescription[i] + "\n";

				}

				break;

			default:

			}

			if (obj.type == undefined){

				var blnchecked = false;

				for (var j = 0; j < obj.length; j++){

					if (obj[j].checked){

						blnchecked = true;

					}

				}

				if (!blnchecked){

					alertMsg += " - " + fieldDescription[i] + "\n";

				}

			}

		}

	}
 

	if (alertMsg.length == l_Msg){

		return true;

	}else{

		alert(alertMsg);

		return false;

	}

}

// -->

</script>
 
 
 

<!--SAMPLE FORM -------------------------------->

<form name="formcheck" onsubmit="return formCheck(this);">

First Name: <input type=text name="FirstName" size="25"><br>

Last Name: <input type=text name="LastName" size="25"><br>

<input type=submit value="Submit Form">

</form>

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

757 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

22 Experts available now in Live!

Get 1:1 Help Now