Forum Moderators: open

Message Too Old, No Replies

newbie: putting js in a separate file

         

patricia_e

3:13 pm on Oct 28, 2004 (gmt 0)

10+ Year Member



Hi,
I know this question is probably very much on the "supposed-to-know" end of things.... but I'll ask anyway.

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?

RonPK

4:04 pm on Oct 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> it no longer works

That's a bit vague... Any error messages?

Maybe your .js file contains the <script> tag and the CDATA stuff? If so, they probably cause problems. Delete them.

patricia_e

4:35 pm on Oct 28, 2004 (gmt 0)

10+ Year Member



RonPK, Yes! This worked! Thank you!