Solved

Required fields in form

Posted on 2008-10-03
6
255 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
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…

932 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

11 Experts available now in Live!

Get 1:1 Help Now