Jump to content

need help with validation


dezkit

Recommended Posts

Every time i press submit when i have phone filled out, it says i didnt fill itout.

 

<script language="JavaScript">
<!--

function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("FullName", "Phone");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Full Name", "Phone");
// 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>



<form action="/site/index.php?page=thanks" method="post" onsubmit="return formCheck(this);">
<label style="float:left;width:20px;"> </label><label style="float:left;width:140px;">Full Name<font color="red">*</font>:</label><input type="text" name="FullName" id="Phone" value="" maxlength="" style="width:180px;"><div style="clear:left;height:0px;"> </div>

<label style="float:left;width:20px;"> </label><label style="float:left;width:140px;">Age:</label><input type="text" name="Age" id="Phone" value="" maxlength="" style="width:180px;"><div style="clear:left;height:0px;"> </div>

<label style="float:left;width:20px;"> </label><label style="float:left;width:140px;">Phone<font color="red">*</font>:</label><input type="text" name="Phone" id="Phone" value="" maxlength="" style="width:180px;"><div style="clear:left;height:0px;"> </div>

<label style="float:left;width:20px;"> </label><label style="float:left;width:140px;">E-Mail:</label><input type="text" name="Email" id="Phone" value="" maxlength="" style="width:180px;"><div style="clear:left;height:0px;"> </div>

<label style="float:left;width:20px;"> </label><label style="float:left;width:140px;">AIM Screen Name:</label><input type="text" name="AIM" id="Phone" value="" maxlength="" style="width:180px;"><div style="clear:left;height:0px;"> </div>

<label style="float:left;width:20px;"> </label><label style="float:left;width:140px;">Myspace URL:</label><input type="text" name="Myspace" id="Phone" value="" maxlength="" style="width:180px;"><div style="clear:left;height:0px;"> </div>

<br>
<center>
<input type='submit' value='Submit'>
<input type="reset" value="Reset">
</center>
</body>

 

 

i know all the id's are set to phone but im too lazy to remove it.

Link to comment
Share on other sites

Having all set to phone was one of your main problems...

 

 

<script language="JavaScript">
<!--

function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("FullName", "Phone");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Full Name", "Phone");
// 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":
			if (obj.value == "" || obj.value == null){
				alertMsg += " - " + fieldDescription[i] + "\n";
			}
			break;
		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){
	alert(alertMsg);
	return false;
}
document.myform.submit();
}
// -->
</script>



<form action="/site/index.php?page=thanks" method="POST" name="myform" onsubmit="return formCheck(this);">
<label style="float:left;width:20px;"> </label><label style="float:left;width:140px;">Full Name<font color="red">*</font>:</label><input type="text" name="FullName" id="FullName" value="" maxlength="" style="width:180px;"><div style="clear:left;height:0px;"> </div>

<label style="float:left;width:20px;"> </label><label style="float:left;width:140px;">Age:</label><input type="text" name="Age" id="Age" value="" maxlength="" style="width:180px;"><div style="clear:left;height:0px;"> </div>

<label style="float:left;width:20px;"> </label><label style="float:left;width:140px;">Phone<font color="red">*</font>:</label><input type="text" name="Phone" id="Phone" value="" maxlength="" style="width:180px;"><div style="clear:left;height:0px;"> </div>

<label style="float:left;width:20px;"> </label><label style="float:left;width:140px;">E-Mail:</label><input type="text" name="Email" id="Email" value="" maxlength="" style="width:180px;"><div style="clear:left;height:0px;"> </div>

<label style="float:left;width:20px;"> </label><label style="float:left;width:140px;">AIM Screen Name:</label><input type="text" name="AIM" id="AIM" value="" maxlength="" style="width:180px;"><div style="clear:left;height:0px;"> </div>

<label style="float:left;width:20px;"> </label><label style="float:left;width:140px;">Myspace URL:</label><input type="text" name="Myspace" id="Myspace" value="" maxlength="" style="width:180px;"><div style="clear:left;height:0px;"> </div>

<br>
<center>
<input type='submit' value='Submit'>
<input type="reset" value="Reset">
</center>
</body>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.