View Single Post
  #3 (permalink)  
Old Feb 10th, 2008, 18:04
psycho wolvesbane psycho wolvesbane is offline
Junior Member
Join Date: Feb 2008
Location: England
Age: 21
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form validation help!

I just tried that but for some reason it just completely ignored the Javascript and even the alert to just submit anyway. I do not have javascript disabled on my browser as my other form (with 1 text box entry) works just fine, but the main problem was trying to get it to work with multiple form entries and functions.

Heres the code atm
Code: Select all
<?php
include "connect_details.php";
?>

<html>
<head>
<title>Clothing Line</title>
<link href="stylesheetCL.css" rel="stylesheet">
<?php require('jscript.inc') ?>

<script language='JavaScript' type='text/JavaScript'>
<!--

function ValCampusName(elem)
{
   if(document.getElementById('Campus').value.length<1)
   {
      document.getElementById('Campus').focus();
      document.getElementById('mySpan1').innerHTML='Please Enter the Campus Name!';
      return false
   }
   else
   {
      return true
   }

}

function ValCampusEmail(elem) 
{
   var emailRegxp = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;
   var emailAddress = document.getElementById('CampusEmail').value;

   if(emailAddress.length < 5 || emailRegxp.test(emailAddress) != true) 
   {
      document.getElementById('CampusEmail').focus();
      document.getElementById('mySpan1').innerHTML='Please Enter a Valid Campus Email!';
      return false;
   }
   else
   {
   return true;
   }
}

function Validate(form)
{
   var Errors = ""; 
   Errors += ValCampusName(form.Campus.value);
   Errors += ValCampusEmail(form.CampusEmail.value);

   if (Errors != "") 
   { 
      return false
   } 
   else 
   { 
      return true
   }
}
//-->
</script>   

</head>
<body>

<?php require('header.inc') ?>
<?php require('menu.inc') ?>

<div style="position:absolute; top:5px; left:200px; width:550px">

<span class="head3">New Campus Form</span><br><br>
  
<form method="POST" action="add_campus_details_php.php" name="AddCampus" onsubmit="alert(Validate(this)); return false;">

<span id="mySpan1" class="errmsg"></span><br>
Campus Name: <input type="text" name="Campus"/><br><br>

<span id="mySpan2" class="errmsg"></span><br>   
Campus Email: <input type="text" size="45" name="CampusEmail"/><br><br>

<input type="submit" name="SubmitB" value="Submit"/>
</form>  
<br><br><br><br>

<a href="display_campus_details.php?Action=Edit">Back to Edit Campus Details List</a>
</div>

</body>
</html>
Reply With Quote