Link to home
Start Free TrialLog in
Avatar of chwankok
chwankok

asked on

Separate htm and js

I have this script which included in .htm file. What i want to do is to create another file as .js

And call this script from htm from js.

Basically  i want to 2 files than everything work in htm.
It would be more tedious this way.

What do i need to modify and add?  
Please let me in detail ya.

Thank you

<script language=JavaScript><!--
function signup_Validator(theForm)
{


if (theForm.contact.value == "")
  {
    theForm.contact.focus();
    alert("Please enter a value for the \"contact.\" field.");
    return (false);
  }
  if (theForm.contact.value.length < 20)
  {
    theForm.contact.focus();
    alert("Please enter at least 20 characters in the \"contact.\" field");
    return (false);
  }
  if (theForm.contact.value.length > 50)
  {
    theForm.contact.focus();
    alert("Please enter at most 50 characters in the \"contact.\" field");
    return (false);
  }

return (true);
}
//--></script>


<form method="post" action="member.asp" name="login" onsubmit="return sinup_Validator(this)">

Avatar of knightEknight
knightEknight
Flag of United States of America image

create a file called myjs.js that looks like this:


function signup_Validator(theForm)
{


if (theForm.contact.value == "")
 {
   theForm.contact.focus();
   alert("Please enter a value for the \"contact.\" field.");
   return (false);
 }
 if (theForm.contact.value.length < 20)
 {
   theForm.contact.focus();
   alert("Please enter at least 20 characters in the \"contact.\" field");
   return (false);
 }
 if (theForm.contact.value.length > 50)
 {
   theForm.contact.focus();
   alert("Please enter at most 50 characters in the \"contact.\" field");
   return (false);
 }

return (true);
}



then in your .htm file, do this:


<HTML>
<HEAD>
<SCRIPT src='myjs.js'></script>
</head>
<BODY>
<form method="post" action="member.asp" name="login" onsubmit="return sinup_Validator(this)">


ASKER CERTIFIED SOLUTION
Avatar of indiatimes
indiatimes

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you might want to include the language in your script tag:

<SCRIPT language='javascript' src='myjs.js'></script>
Avatar of chwankok
chwankok

ASKER

Thank you guy.