Error on Loading Page from Link

Giganews Newsgroups
Subject: Error on Loading Page from Link
Posted by:  Andrew V. Romero (rrstudi…@icqmail.com)
Date: Thu, 10 Jul 2003

I have a script that I am working on for an intranet tool and in this
script I have a form, which when submitted the onSubmit command calls
calculate().  In this calculate function, I have it do some calculations
and write out a new document using document.write().  One of the lines
it writes is (the whole script is at the bottom of this email).
pageData = PageData+"<b>Patient Data</b><br>Wt: "+weight+"
"+weightUnits+" &nbsp&nbsp Ht: "+height+"in &nbsp&nbsp Gender:
"+gender+"<br><a href=\"index.html\">Back To Form</a>";

When I click on this link to "reload" the page and have the original
form show up again, it works but in the javascript console i get errors
saying:
-The link to
file:///C:/Server/Apache%20Group/Apache2/htdocs/heparin/index.html was
blocked by the security manager.
Remote content may not link to local content.

-Error: uncaught exception: Load of
file:///C:/Server/Apache%20Group/Apache2/htdocs/heparin/index.html denied.

The basic goal of the link is to destory the page that was written by
the funtion and to just display the form again.
I am not a computer programmer by training, so maybe I am going about
this wrong.  Please let me know how to get rid of these error messages.
  If you have any other tips on things that I am doing strange in this
script, let me know.  I am fairly familier with java and PHP, but this
is my first real dealings with javascript.

Thanks,
    Andrew V. Romero

--The Whole Script--
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="Andrew V. Romero" content="romero">
    <meta name="GENERATOR" content="Mozilla/4.7 [en] (Win98; U) [Netscape]">
    <title>UMC Out of Range Heparin Protocol</title>
</head><body background="coctail3.gif" link="#0000DD" vlink="#0000DD"
alink="#0000DD">
<center><font size=+3>UMC Demo Heparin Protocol</font><font
size=+3></font></center><br>

<script language="JavaScript">

function calculate()
{
    if (document.form.weight.value != "" && document.form.height.value !=
"" && document.form.age.value != "")
    {
        //0 is kg
        if (document.form.wtUnits[0].checked)
        {
            weight = document.form.weight.value;
            weightUnits = "kg"
        }
        else if (document.form.wtUnits[1].checked)
        {
            weight = document.form.weight.value / 2.2
            weightUnits = "lbs"
        }

        height = document.form.height.value;
        age =  document.form.age.value;

        var rate;
        var gender;
        var bolus;

        //for males
        if (document.form.gender[0].checked)
        {
            gender = "male"
            //AMI
            if (document.form.diagnosis[0].checked)
            {
                rate = -336.4 + (6.52*weight) + (22*height) - (7.52*age)
            }
            //USA
            else if (document.form.diagnosis[1].checked)
            {
                rate = -336.4 + (6.52*weight) + (22*height) - (7.52*age) - 142
            }
            //AFib
            else if (document.form.diagnosis[2].checked)
            {
                rate = -336.4 + (6.52*weight) + (22*height) - 7.52 - 142

            }
        }

        //for females
        else if (document.form.gender[1])
        {
            gender = "female"
            //AMI
            if (document.form.diagnosis[0].checked)
            {
                rate = -336.4 + (6.52*weight) + (22*height) + (2.71*age) - 749.2
            }
            //USA
            else if (document.form.diagnosis[1].checked)
            {
                rate = -336.4 + (6.52*weight) + (22*height) + (2.71*age) - 672.3
            }
            //AFib
            else if (document.form.diagnosis[2].checked)
            {
                rate = -336.4 + (6.52*weight) + (22*height) + (2.71*age) - 672.3
            }
        }

        //AMI USA or AFib bolus
        if (document.form.diagnosis[0] || document.form.diagnosis[1] ||
document.form.diagnosis[2])
        {
            //want bolus
            if (document.form.bolus[0].checked)
            {
                bolus = 50 * weight;
            }
            //doesn't want bolus
            else if (document.form.bolus[1].checked)
                bolus = "No Bolus Requested";
        }

        //DVT and PE bolus and infusion
        if (document.form.diagnosis[3].checked)
        {
            alert("test");
            rate = 18 * weight;
            //if want bolus
            if (document.form.bolus[0].checked)
            {
                bolus = 80 * weight;
            }
            //doesn't want bolus
            else if (document.form.bolus[1].checked)
                bolus = "No Bolus Requested";
        }

        var pageData;
        pageData = "<html><head><meta http-equiv=\"Content-Type\"
content=\"text/html; charset=iso-8859-1\"><meta name=\"Andrew V.
Romero\" content=\"romero\"><title>UMC Out of Range Heparin
Protocol</title></head><body background=\"coctail3.gif\"
link=\"#0000DD\" vlink=\"#0000DD\" alink=\"#0000DD\"><center><font
size=+3>UMC Demo Heparin Protocol</font><font size=+3></font></center>";
        pageData = PageData+"<b>Patient Data</b><br>Wt: "+weight+"
"+weightUnits+" &nbsp&nbsp Ht: "+height+"in &nbsp&nbsp Gender:
"+gender+"<br><a href=\"index.html\">Back To Form</a>";
        alert ("Infusion Rate: "+rate+" units/hr "+gender);

        document.write(pageData);
        document.close();
    }

    else
        alert ("Please Fill In All Fields");
}

</script>

<form name="form" method="get" action="" onSubmit=calculate();>
<table border =1>
    <tr><td colspan=3><b>Patient Data</b></td></tr>
    <tr><td><b>Weight (kg)</b></td><td><input name="weight" size=5><input
type="radio" name="wtUnits" value="kg" checked>Kg &nbsp&nbsp<input
type="radio" name="wtUnits" value="lb">lbs</td></tr>
    <tr><td><b>Height (in)</b></td><td><input name="height" size=3></td></tr>
    <tr><td><b>Age</b></td><td><input name="age" size=3></td></tr>
    <tr><td><b>Gender</b></td><td><input type="radio" name="gender"
value="male" checked>Male &nbsp&nbsp <input type="radio" name="gender"
value="female">Female</td></tr>
    <tr><td><b>Diagnosis</b> </td><td><input type="radio" name="diagnosis"
value="AMI" checked>AMI &nbsp&nbsp <input type="radio" name="diagnosis"
value="USA">USA &nbsp&nbsp <input type="radio" name="diagnosis"
value="AFib">Afib &nbsp&nbsp<input type="radio" name="diagnosis"
value="DVTorPE">DVT or PE</td></tr>
    <tr><td><b>Bolus</b></td><td><input type="radio" name="bolus"
value="yes" checked>Yes &nbsp&nbsp <input type="radio" name="bolus"
value="no">No</td></tr>
</table>
<div align=right><br><input TYPE = "submit" Value = "  Calculate
"></div></form>
<hr><br>

</form>
</body>
</html>

Replies