Setting up myscripts.js files

Hello. I would like to know how to call a Java script functions from a 'myscripst.js' file and use it in the mortgage_form.htm page. The pages are supplied below. I have read that this is not difficult but I can no seem to get it to work.
Thank you in advance
Clive Foyster


/\/\/\/\/\/\/\/\/\/\/\/\ = mortgage_form.htm
<table>
  <tr>
    <td><form method="POST">
      <b><p>Mortgage Calculator</b></p>
    </form>
    </td>
  </tr>
  <tr>
    <td>Principal: </td>
    <td>$ </td>
    <td><input TYPE="TEXT" NAME="principal" SIZE="9" onChange="computeField(this, false)"></td>
  </tr>
  <tr>
    <td>Interest: </td>
    <td></td>
    <td><input TYPE="TEXT" NAME="interest" SIZE="9" onChange="computeField(this, false)">%</td>
  </tr>
  <tr>
    <td>Duration:</td>
    <td></td>
    <td><input TYPE="TEXT" NAME="years" SIZE="9" onChange="computeField(this, false)">yrs</td>
  </tr>
  <tr>
    <td><input TYPE="reset" VALUE="Reset" onClick="clearForm(this.form)"></td>
    <td></td>
    <td><input TYPE="button" VALUE="Calculate" onClick="computeForm(this.form, true)"></td>
  </tr>
  <tr>
    <td>Payment:</td>
    <td>$</td>
    <td><input TYPE="TEXT" NAME="payment" SIZE="9" onChange="computeField(this, false)">/mth</td>
  </tr>
</table>


\/\/\/\/\/\/\/\/\/\= myscripts.js
script for mortgage calculation
<script LANGUAGE="JavaScript" name="mortage_calc">
<!--

function checkNumber(input, min, max, msg)
{
    msg = msg + " field has invalid data: " + input.value;

    var str = input.value;
    for (var i = 0; i < str.length; i++)
      {
        var ch = str.substring(i, i + 1)
        if ((ch < "0" || "9" < ch) && ch != '.')
            {
            alert(msg);
            return false;
        }
    }
    var num = parseFloat(str)

    if (num < min || max < num)
      {
        alert(msg + "\n must be between " + min + " and " + max);
        return false;
    }
    input.value = str;

    return true;
}


function computeField(input, buttonFlag)
{
    if (input.value != null && input.value.length != 0)
        input.value = "" + eval(input.value);
    computeForm(input.form, buttonFlag);
}


function computeForm(form, buttonFlag)
{
    if((form.years.value == null || form.years.value.length == 0) ||
         (form.interest.value == null || form.interest.value.length == 0) ||
         ((form.principal.value == null || form.principal.value.length == 0) &&
         (form.payment.value == null || form.payment.value.length == 0)))
      {
          if(buttonFlag == true)
          alert("Please supply enough information to calculate.")
       
            return;
    }

    if(form.years.value != null && form.years.value.length != 0 &&
         form.interest.value != null && form.interest.value.length != 0 &&
         form.principal.value != null && form.principal.value.length != 0 &&
         form.payment.value != null && form.payment.value.length != 0)
            form.payment.value = "";      

      var i = form.interest.value / 1200.0;
      
      var pow = 1;
      for (var j = 0; j < form.years.value*12; j++)
            pow = pow * (1 + i);

      if(form.principal.value == null || form.principal.value.length == 0)
      {
            if (!checkNumber(form.years, 1, 30, "# of years") ||
                  !checkNumber(form.interest, .001, 99, "Interest") ||
                  !checkNumber(form.payment, 1, 100000, "Payment"))
            {
                  form.principal.value = "Invalid";
                  return;
            }
         
          form.principal.value = Math.round((form.payment.value * (pow-1) ) / (pow * i))
      }
      else if(form.payment.value == null || form.payment.value.length == 0)
      {
            if (!checkNumber(form.years, 1, 30, "# of years") ||
                  !checkNumber(form.interest, .001, 99, "Interest") ||
                  !checkNumber(form.principal, 100, 10000000, "Principal"))
            {
                  form.payment.value = "Invalid";
                  return;
            }

            form.payment.value = Math.round(100.0*(form.principal.value * pow * i) / (pow - 1)) / 100.0
      }
}


function clearForm(form)
{
    form.years.value = "";
    form.interest.value = "";
    form.principal.value = "";
      form.payment.value = "";
}

//-->
</script>
clive1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oubelkasCommented:
You must include the file in your html page and then you can call up the functions, just use :

<script language="javascript" src="myscripts.js"></script>

of course the source must exist.

J.

0
Michel PlungjanIT ExpertCommented:
Also if your server is IIS3 or some other server that does not default understand js files, you will need to amend the mime type settings so .js is associated with
application/x-javascript

Michel
0
HazemCommented:
Hi;

at the begining of the ortgage_form.htm
files after the <HTML> tag add this:
<HEAD>
<script language="javascript" src="myscripts.js"></script>
</HEAD>

that's all;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Michel PlungjanIT ExpertCommented:
Hazem: This is the second time you answer a question where a comment already has answered it and the person commenting is waiting for the person who asked the question to either ask for more info or to say, thank, go ahead and post as an answer.

Please spend a little more time looking at the way we do this before you start hunting points by giving unrealted answers or using code already posted in a previous comment like here.

Michel
0
oubelkasCommented:
YEAH, just what Michel says, pay attention to the other comments Hazem. As you can see I already SAID SO!!

Dive1> reject the answer of Hazem since it has already been said....


J.
0
Michel PlungjanIT ExpertCommented:
Joseph: It is Clive, not Dive and no need to shout or get exited ;-)
Michel
0
oubelkasCommented:
Oh, sorry, just got uncontroled.....pleaze excuse me.....just can't stand the fact people keep answering questions if the are already commented.
and WHOOPS! Also sorry for misspelling the name....it just looked like dive because the c and l are as if they are sticked together and therefore look like a d.

Can you forgive me, C L I V E? ;)

J.

0
HazemCommented:
Hi;

There is an error in the myscripts.js file:

u should remove
<script LANGUAGE="JavaScript" name="mortage_calc">
:
:
:
</script>

just list the function and variables u want in the file.
0
Michel PlungjanIT ExpertCommented:
Hazem is correct. js files may NOT contain any html and the <!-- --> to hide the javascript are needless anyway since the file will not be loaded if javascript is not active or present..

Michel

0
clive1Author Commented:
Thank's for the answer Hazem. Appreciate the help from Michel and Oulbekas as well.
Many thanks,
Clive
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.