View Full Version : Javascript stops working

03-23-2009, 03:44 AM
I have a form that calls a javascript function to validate a date:

<form name="frmSelect" method="Post" action="allxml.asp" onSubmit="return ValidateForm()">

the function is called if I only have a little bit of code like this:

<script language="javascript">

function ValidateForm()

alert("matchArray = null");



but once I add all of the code the validation doesn't run.
any Ideas what the problem could be?

part of my code:

<?xml version="1.0" encoding="UTF-16"?>
<title>Time </title>
<script language="javascript">

function ValidateForm()
var dteDate;
var day, month, year;
var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
var matchArray = dt.match(datePat);

if (matchArray == null){
alert("matchArray = null");
return false;
month = matchArray[1];
day = matchArray[3];
year = matchArray[5];

dteDate=new Date(year,month,day);
if((day==dteDate.getDate()) &amp;&amp; (month==dteDate.getMonth()) &amp;&amp; (year==dteDate.getFullYear()))
return true;
alert("invalid date - day " +day+" month " +month+" year "+ year);
return false

<form name="frmSelect" method="Post" action="allxml.asp" onSubmit="return ValidateForm()">

03-23-2009, 08:54 AM
There might be some error in your javascript code. To debug this, get a copy of firebug (https://addons.mozilla.org/firefox/addon/1843) for your firefox first(if you don't have one)

After that change your input's type from submit to button and then move the function call from the onsubmit of your form to the onclick of your button. You could then find the erroneous statement with the help of firebug. After sorting the error, you may revert it.

<form name="frmSelect" method="Post" action="allxml.asp" >
<input type="button" onclick="return ValidateForm();" value="Submit"/>

PS: validate and fix all the errors (http://validator.w3.org/#validate_by_input) in your markup.

03-23-2009, 03:24 PM
Thank you the second link helped

I think DocTYPE was the problem this is the change to the html file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
<META http-equiv="Content-Type" content="text/html; charset=UTF-16">

and this is the change to the xsl file that tranformes an xml file:

<xsl:output method="html"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" indent="yes"/>