Include another file in a script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew V. Romero

    #1

    Include another file in a script

    I am using javascript to parse a form and it uses the information on
    that form to display some calculations (yes using PHP or something would
    be easier, but not feasible for this project). So I would like to
    include another file on my display page if a certain variable is
    checked. My code is something like this.

    <script type="text/javascript">
    .......lots of code here
    if (x.TPNroute == "peripheral ")
    {
    pageData=pageDa ta+"<br><b>Note s for Peripheral TPNs</b></br>"+
    "<li>Dextro se should be <u><</u> 12.5%</li>"+
    "<li>Calciu m should be <u><</u> 8 meq/L</li>"
    }

    pageData+="<br> <b>All 3-in-1 TPNs should have at least 2.5% lipids for
    stability purposes</b>"
    document.write( pageData);


    if (x.displayRules == "yes")
    {
    alert("test");
    src="TPNrules.j s";
    }
    document.close( );
    </script>

    The TPNrules.js file looks like
    document.write( "This is a test");

    I want the contents of the TPNrules.js file to be displayed if
    displayRules == true. It will be a lot of text which is why I don't
    really want to put it just in the script itself, having another file
    with the rules would make things look simplier. So how can I have the
    contents of the file displayed? I know I am not using the right command
    for this, but can't figure out which I should use.

    Thanks for any ideas,
    Andrew V. Romero

  • Andrew V. Romero

    #2
    Re: Include another file in a script

    Okay, I figured out one way to do it

    document.write( pageData);

    //includes a seperate file (TPNrules.js) if user wants all rules displayed.
    if (x.displayRules == "yes")
    {
    document.write( "<hr width=\"100%\" size=2><script
    type=\"text/javascript\" src=\"TPNrules. js\"></"+"script>" );
    }
    document.close( );

    Thank anyway,
    Andrew V. Romero


    Andrew V. Romero wrote:[color=blue]
    > I am using javascript to parse a form and it uses the information on
    > that form to display some calculations (yes using PHP or something would
    > be easier, but not feasible for this project). So I would like to
    > include another file on my display page if a certain variable is
    > checked. My code is something like this.
    >
    > <script type="text/javascript">
    > ......lots of code here
    > if (x.TPNroute == "peripheral ")
    > {
    > pageData=pageDa ta+"<br><b>Note s for Peripheral TPNs</b></br>"+
    > "<li>Dextro se should be <u><</u> 12.5%</li>"+
    > "<li>Calciu m should be <u><</u> 8 meq/L</li>"
    > }
    >
    > pageData+="<br> <b>All 3-in-1 TPNs should have at least 2.5% lipids for
    > stability purposes</b>"
    > document.write( pageData);
    >
    >
    > if (x.displayRules == "yes")
    > {
    > alert("test");
    > src="TPNrules.j s";
    > }
    > document.close( );
    > </script>
    >
    > The TPNrules.js file looks like
    > document.write( "This is a test");
    >
    > I want the contents of the TPNrules.js file to be displayed if
    > displayRules == true. It will be a lot of text which is why I don't
    > really want to put it just in the script itself, having another file
    > with the rules would make things look simplier. So how can I have the
    > contents of the file displayed? I know I am not using the right command
    > for this, but can't figure out which I should use.
    >
    > Thanks for any ideas,
    > Andrew V. Romero
    >[/color]

    Comment

    Working...