Forum Moderators: open
I have validation js in php forms pages on my site. The validation works fine when I have it in the form .php page but when I pull it out and put it in a separate .js file, it no longer works.
Can someone point me to what piece of knowledge I'm missing?
Here's a fragment of the code:
<script type="text/javascript">
//<![CDATA[function isBlank(testStr)
{
if (testStr.length == 0) // nothing entered?
{return true;}
for (var i = 0; i <= testStr.length-1; i++) // all spaces?
{
if (testStr.charAt(i)!= " ")
{return false;}
}
return true;
}
function checkForm(form)
{
if (isBlank(form.firstName.value))
{
alert("Please enter your first name.");
form.firstName.focus();
return false;
}
The //<![CDATA[ stuff is so that it's xhtml compliant.
Also, when I do the include (putting the js in a separate file), I do it like this:
<script src="regRadioOnly_noDB_val.js" type="text/javascript"></script>
Any ideas? Could it be that I am using the DOM incorrectly?