Link to home
Start Free TrialLog in
Avatar of cdloves
cdloves

asked on

Moving javascript codes to external file

I am trying to use this script

http://www.dynamicdrive.com/dynamicindex2/crosstick.htm

However, the script is too long and I want to move it to external file.  I tried to save the file as "name.js"
then use the following line in body to call it:

===========
SCRIPT LANGUAGE="JavaScript1.2" SRC="name.js" TYPE='text/javascript'>
            /*
                  Submit Once form validation-
                  © Dynamic Drive (www.dynamicdrive.com)
                  For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
                  */
      ></SCRIPT>
==========

The script works while in the body tag but wouldn't work when I try to move it to external page.  Is it possible to move it out at all? (dynamicdrive, the creator is okay with user moving the file to external file)
Avatar of YZlat
YZlat
Flag of United States of America image

you'll need to declare your external file in the <head> section of the page:

<script LANGUAGE="JavaScript1.2" SRC="name.js" TYPE="text/javascript"></script>,
that's all. If it does not work, then the error must be either in the file path or the file itself
is your name.js file located in the same folder?
Avatar of cdloves
cdloves

ASKER

YZlat,

Nope that doesn't work either.  The javacode works when it's in the actual page, but not when in external file.  The file path is right, it is in same folder.  

(points increased to 500)
ASKER CERTIFIED SOLUTION
Avatar of Timbo87
Timbo87

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
Avatar of cdloves

ASKER

Getting closer, Timbo87.

The msg is now displayed but it doesn't display at the right location.  Its supposed to display in in cell 2,3 of the table, but instead, it's displayed outside the table box.

Anyway to fix this?  Thanks
Place this code:

<ilayer id="main" width=&{scrollerwidth}; height=&{scrollerheight}; bgColor=&{scrollerbgcolor}; background=&{scrollerbackground}; visibility=hide>
<layer id="first" left=0 top=1 width=&{scrollerwidth};>
<script language="JavaScript1.2">
if (document.layers)
document.write(messages[0])
</script>
</layer>
<layer id="second" left=0 top=0 width=&{scrollerwidth}; visibility=hide>
<script language="JavaScript1.2">
if (document.layers)
document.write(messages[dyndetermine=(messages.length==1)? 0 : 1])
</script>
</layer>
</ilayer>

in the <TD> of the desired cell.
Make sure you still have:

<SCRIPT LANGUAGE="JavaScript1.2" SRC="name.js" TYPE='text/javascript'>
          /*
               Submit Once form validation-
               © Dynamic Drive (www.dynamicdrive.com)
               For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
               */
     ></SCRIPT>

In the <HEAD>
Avatar of cdloves

ASKER

<HTML>
<HEAD><TITLE>Your Company Name</TITLE>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="script.js" TYPE='text/javascript'>
          /*
               Submit Once form validation-
               © Dynamic Drive (www.dynamicdrive.com)
               For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
               */
     </SCRIPT>

</HEAD>
<BODY>
      <TABLE BORDER = 1 ALIGN="center" WIDTH="750">
            <TR><TD COLSPAN="3"></TD></TR>
            <TR bgcolor="black"><TD COLSPAN="3">&nbsp;</TD></TR>
            <TR>
            <TD Name="left" VALIGN="top" WIDTH="120px" background="" COLSPAN="1">S<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>S</TD>
            <TD Name="body" VALIGN="top" WIDTH="430px"></TD>
            <TD Name="right" VALIGN="top" Width="200px">___
                  <ilayer id="main" width=&{scrollerwidth}; height=&{scrollerheight}; bgColor=&{scrollerbgcolor}; background=&{scrollerbackground}; visibility=hide>
                  <layer id="first" left=0 top=1 width=&{scrollerwidth};>
                  <script language="JavaScript1.2">
                  if (document.layers)
                  document.write(messages[0])
                  </script>
                  </layer>
                  <layer id="second" left=0 top=0 width=&{scrollerwidth}; visibility=hide>
                  <script language="JavaScript1.2">
                  if (document.layers)
                  document.write(messages[dyndetermine=(messages.length==1)? 0 : 1])
                  </script>
                  </layer>
                  </ilayer>

            </TR>
            <TR bgcolor="black"><TD COLSPAN=3 ALIGN="center"> <FONT COLOR="white"></FONT></TD></TR>
      </TABLE>
<BODY>
</HTML>
Avatar of cdloves

ASKER

above is my page info, but the msg is not in the <TD> where it belongs to.  the JS file is called "script.js"
Hmm, I was wrong. It looks like you just need the <SCRIPT> tag.

<HTML>
<HEAD><TITLE>Your Company Name</TITLE>


</HEAD>
<BODY>
     <TABLE BORDER = 1 ALIGN="center" WIDTH="750">
          <TR><TD COLSPAN="3"></TD></TR>
          <TR bgcolor="black"><TD COLSPAN="3">&nbsp;</TD></TR>
          <TR>
          <TD Name="left" VALIGN="top" WIDTH="120px" background="" COLSPAN="1">S<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>S</TD>
          <TD Name="body" VALIGN="top" WIDTH="430px"></TD>
          <TD Name="right" VALIGN="top" Width="200px">___
            <SCRIPT LANGUAGE="JavaScript1.2" SRC="script.js" TYPE='text/javascript'>
                /*
               Submit Once form validation-
               © Dynamic Drive (www.dynamicdrive.com)
               For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
               */
                 </SCRIPT>
          </TD>
          </TR>
          <TR bgcolor="black"><TD COLSPAN=3 ALIGN="center"> <FONT COLOR="white"></FONT></TD></TR>
     </TABLE>
<BODY>
</HTML>
Avatar of cdloves

ASKER

It still didn't move the msg window to the right location though...
Avatar of cdloves

ASKER

Finally got it to work, I have to remove the <SCRIPT> tag in the head section.
Yes, I have removed that in the complete version posted above.
Avatar of cdloves

ASKER

Thanks for the help all.
Avatar of cdloves

ASKER

Oh, I didn't notice that.  I thought the <div>, etc. tags were the only ones you removed.

Thanks again for the help.
Avatar of cdloves

ASKER

Tim,

Are you still reading this by any chance? I need your helping still.
Yes?
Avatar of cdloves

ASKER

I just tested the modified code and it doesn't work for Netscape 6.  Only the first two links are showed, then it stops completely.  Do you think you could help me fix it?  I'll make a new question and award you another 500 points once done.

Thanks in advance.
Add this to the <TD>

              <ilayer id="main" width=&{scrollerwidth}; height=&{scrollerheight}; bgColor=&{scrollerbgcolor}; background=&{scrollerbackground}; visibility=hide>
               <layer id="first" left=0 top=1 width=&{scrollerwidth};>
               <script language="JavaScript1.2">
               if (document.layers)
               document.write(messages[0])
               </script>
               </layer>
               <layer id="second" left=0 top=0 width=&{scrollerwidth}; visibility=hide>
               <script language="JavaScript1.2">
               if (document.layers)
               document.write(messages[dyndetermine=(messages.length==1)? 0 : 1])
               </script>
               </layer>
               </ilayer>