I am a php programmer and I have no background in Javascripts. I made this form and my boss told me to put in form validation using java scripts on the page. Here is my attempt but it just submits as if everything is ok.
My thoughts on how it is supposed to wrok is that when the submit button is clicked the ValidateForm function is called and processed. Each error line checks out the text box or dropdown and reutrns an error msg (with which area is not filled out). Then the error msg is displayed in an alert popup box. Thanks in advance.
Code:
html>
<head>
<title>Client Equipment</title>
</head>
<body>
<h2 align="left">Aspex POS Employee Form</h2>
<p align="left"> Client Equipment Information </p>
<p align="left">
<form action="eclientcase.php" method="post" name="mySubmit" style="width:320">
<?php
CreateHiddenText("ClientName",$ClientName);
CreateHiddenText("ClientLoc",$ClientLoc);
CreateHiddenText("Comp",$Comp);
CreateHiddenText("OS",$OS);
CreateHiddenText("AspexVer",$AspexVer);
CreateHiddenText("MicroChargeVer",$MicroChargeVer);
CreateHiddenText("Updateformat",$Updateformat);
?>
<p>Name: <?php echo $ClientName; ?></p>
<p>Address: <?php echo $ClientLocation; ?></p>
<?php
$Cat1 = $_POST['Category1'];
$Cat2 = $_POST['Category2'];
$Cat3 = $_POST['Category3'];
echo '<select name="Category1" onchange="this.form.submit()" selected='.$Cat1.'>';
echo "<option value=\" \">Choose Category 1</option><br>";
PopulateCategories(1,"None",$Cat1);
echo '</select>';
if($Cat1 != "Other"){
echo '<p><select name="Category2" onchange="this.form.submit()" selected='.$Cat2.'>';
echo "<option value=\" \">Choose Category 2</option><br>";
PopulateCategories(2,$Cat1,$Cat2);
echo '</select>';
if($Cat2 != "Other"){
echo '<p><select name="Category3" onchange="this.form.submit()" selected='.$Cat3.'>';
echo "<option value=\" \">Choose Category 3</option><br>";
PopulateCategories(3,$Cat2,$Cat3);
echo '</select>';
}else
echo '<input type="text" name="Category3" id="Category3" value="'.$Cat3.'" onchange="this.form.submit()">';
}else
echo '<input type="text" name="Category2" id="Category2" value="'.$Cat2.'" onchange="this.form.submit()">';
?>
</form>
<script language="JavaScript">
<!--
function checkDropdown(sender,choice) {
var error = "";
if (choice == "") {
error = "You didn't choose an ".sender." from the drop down list.\n";
}
return error;
}
function isEmpty(sender,strng) {
var error = "";
if (strng.length == 0) {
error = "The ".sender." text area has not been filled in.\n";
}
return error;
}
function ValidateForm() {
var error = "";
error += isEmpty("Category",mySubmit.Cat1.value);
error += isEmpty("Issue",mySubmit.Issue.value);
error += isEmpty("Cause",mySubmit.Cause.value);
error += isEmpty("Resolution",mySubmit.Resolution.value);
error += isEmpty("Security Level",mySubmit.SecurityLevel.value);
error += checkDropdown("EmpName",mySubmit.Employee.selectedIndex);
if(why != ""){
alert(error);
return false;
}
else return true;
}
//-->
</script>
<form action="submit.php" method="post" name="mySubmit" onSubmit="return ValidateForm()" style="width:320">
<?php
CreateHiddenText("ClientName",$ClientName);
CreateHiddenText("ClientLoc",$ClientLoc);
CreateHiddenText("Comp",$Comp);
CreateHiddenText("OS",$OS);
CreateHiddenText("AspexVer",$AspexVer);
CreateHiddenText("MicroChargeVer",$MicroChargeVer);
CreateHiddenText("Update",$Update);
CreateHiddenText("Cat1",$Cat1);
CreateHiddenText("Cat2",$Cat2);
CreateHiddenText("Cat3",$Cat3);
CreateHiddenText("Updateformat",$Updateformat);
?>
<p align="left"><strong>Case</strong>
<select name="CaseStatus">
<option value='Open' selected>Open</option>
<option value='Follow Up'>Follow Up</option>
<option value='Closed'>Closed</option>
</select>
<p>On Site Visit Required:
<input type="checkbox" name="OnSiteVisit">
<p>On Site Visits Used:
<?php
$Visits = GetClientVal($ClientName,$ClientLoc,"SiteVisits");
echo $Visits;
CreateHiddenText("VisitsUsed",$Visits);
?>
<hr>
<strong>Time Case Opened:</strong>
<?php
$TimeOpen = date('Y-m-d H:i:s');
$Display = date('g:i:s A \o\n n-j-Y ');
CreateHiddenText("TimeOpen",$TimeOpen);
echo $Display;
?><br>
<strong>Issue<br>
</strong>
<textarea name="Issue" cols="37" rows="5" id="Issue" onFocus="if(this.value=='Describe the Issue')this.value='';">Describe the Issue</textarea>
</p>
<p align="left"><strong>Cause</strong><br>
<textarea name="Cause" cols="37" rows="5" id="Cause" onFocus="if(this.value=='Possible Causes')this.value='';">Possible Causes</textarea>
</p>
<p align="left"><strong>Resolution<br>
<textarea name="Resolution" cols="37" rows="5" id="Resolution" onFocus="if(this.value=='What fixed it')this.value='';">What fixed it</textarea>
</strong></p>
<p align="left">Keywords:<br>
<input name="Keywords" type="text" id="Keywords" onFocus="if(this.value=='Insert Here')this.value='';" value="Insert Here" size="50">
</p>
<p align="left">Security Level: (0-255)<br>
<input name="SecurityLevel" type="text" id="SecurityLevel" onFocus="if(this.value=='Your message')this.value='';" value="100" size="5" maxlength="3">
</p>
<hr align="left" width="320">
<p align="left"><strong>Employee Information </strong></p>
<p align="left">Employee Name:
<?php
echo '<select name="EmpName" selected='.$EmpName.'>';
echo "<option value=\"\">Choose Name</option><br>";
PopulateDropdown("Employee","Name",'');
echo "</select>";
?>
</p>
<p align="left">
<input name="Submit" type=submit value="Submit">
</p>
</form>
</p>
<a href="user.php">Function List</a>
</body>
</html>
My thoughts on how it is supposed to wrok is that when the submit button is clicked the ValidateForm function is called and processed. Each error line checks out the text box or dropdown and reutrns an error msg (with which area is not filled out). Then the error msg is displayed in an alert popup box. Thanks in advance.