View Full Version : form validation using java script not working?

05-27-2009, 01:00 PM
form validation using java script not working nothing happens when i press submit button why?

<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Online Bus Ticket Reservation</title>

<script type="text/javascript">

function validExpiryDate(form,monthInputName,yearInputName) {
var month = form[monthInputName].value,
year = form[yearInputName].value,
d = new Date(),
currentYear = d.getFullYear(),
currentMonth = d.getMonth() + 1; //need to add 1, getMonth returns 0-11
if (!/^\d{1,2}$/.test(month) !/^\d{4}$/.test(year)) {
alert('Improper entry!');
return false;
} else if (year < currentYear (year == currentYear && month < currentMonth)) {
alert('Card has expired!');
return false;
return true;

window.onload = function () {
document.payment.onsubmit = function () {
MM_validateForm('fname', '', 'R', 'card_number_field1', '', 'RisNum', 'card_number_field2', '', 'RisNum', 'card_number_field3', '', 'RisNum', 'card_number_field4', '', 'RisNum', 'card_exp_month', '', 'RisNum', 'card_exp_year', '', 'RisNum');
var bool1 = validExpiryDate(this,'card_exp_month','card_exp_year');
var bool2 = document.MM_returnValue;
return (bool1 && bool2);


<link href="obrs.css" rel="stylesheet" type="text/css" />
<!--[if IE 5]>
<style type="text/css">
/* place css box model fixes for IE 5* in this conditional comment */
.twoColFixRtHdr #sidebar1 { width: 220px; }
<![endif]--><!--[if IE]>
<style type="text/css">
/* place css fixes for all versions of IE in this conditional comment */
.twoColFixRtHdr #sidebar1 { padding-top: 30px; }
.twoColFixRtHdr #mainContent { zoom: 1; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<style type="text/css">
.style1 {
color: #FFFF00;
font-weight: bold;
.style2 {
color: #FFFF66;
font-weight: bold;
#payment_box {
height: 300px;
width: 500px;
margin-top: 100px;
margin-left: 150px;
#payment_form {
height: 150px;
width: 400px;
margin-top: 40px;
.style3 {
font-size: 16px;
font-weight: bold;
color: #333333;


<body class="twoColFixRtHdr">

<div id="container">
<div id="header">
<!-- end #header -->
<img src="images/header" alt="OBTRS: Header" /></div>
<div id="sidebar1">
<!-- end #sidebar1 -->
<img src="images/sidebar_slideshow" alt="" /><center><a href="pictureslideshow.html">Click Here</a></center>
<div id="blogarea">
<p class="style2">Casual Dining Restaurants</p>
<p><br />
Our family-style restaurants are the favorite of thousands of tourists and professional drivers alike. Our clean and friendly surroundings encourage people to stop and enjoy a wholesome meal with us when they travel. Our customers recognize our strong teamwork ethic as we provide them quality service.</p>
<p><br />
<span class="style1">Convenience Stores</span></p>
<p><br />
Our cashiers take pride in having the items on the shelf ready for our travelers when they stop. We know many are in a hurry and we need to be &quot;fast&quot; to meet their busy schedules. Some of our returning customers enjoy fresh coffee and we have it ready for them. The joint effort of our managers and associates creates a strong &quot;team spirit&quot; that provides the customers what they are looking for as they travel.</p>
<div id="mainContent">
<div id="nav">
<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','760','height','30','src','images/nav_bar2','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','images/nav_bar2' ); //end AC code
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="760" height="30">
<param name="movie" value="images/nav_bar2.swf" />
<param name="quality" value="high" />
<embed src="images/nav_bar2.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="760" height="30"></embed>

<div class="style3" id="payment_box">

<form name="payment" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<center>Make Payment<br />
<br /><br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Card Holder's Name:&nbsp;*<input name="fname" type="text" id="fname" />
<br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Card Number:
<INPUT name="card_number_field1" type="text" id="card_number_field1" size="4" maxlength="4" />
&nbsp;<INPUT name="card_number_field2" type="text" id="card_number_field2" size="4" maxlength="4">
&nbsp;<INPUT name="card_number_field3" type="text" id="card_number_field3" size="4" maxlength="4">
&nbsp;<INPUT name="card_number_field4" type="text" id="card_number_field4" size="4" maxlength="4">
<br /><br />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Card Expiry Date:&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;<INPUT name="card_exp_month" type="text" id="card_exp_month" size="2" maxlength="2">*
<INPUT name="card_exp_year" type="text" id="card_exp_year" size="4" maxlength="4">
</center><br /><br />
<center><input name="submit" type="submit" value="Submit" /></center>


<!-- end #mainContent -->
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats -->
<br class="clearfloat" />
<div id="footer">
<p><a href="aboutus.html">About us</a> |<a href="feedback.html"> Feedback</a> |<a href="faqs.html"> FAQs</a> | <a href="terms.html">Terms &amp; Conditions</a> | <a href="contactus.html">Contact us</a></p>
<p> 2009 Copyright - Shah Abdul Latif University Khairpur</p>
<!-- end #footer -->
<!-- end #container -->


05-27-2009, 01:12 PM
Where is your MM_validateForm() function?

05-27-2009, 09:40 PM
what does that do? can u show me where the mistake is what should i do?

05-31-2009, 10:17 AM
any one ?

05-31-2009, 10:56 AM
MM_validateform function refers to a script that DW put in for you and it looks like you may have deleted it. Search google for the function and you'll probably find what you need. It needs to be in your document. Also it helps to actually TRY things on your own. We aren't here to hold your hand. We are here to help.