Forums

This topic is locked

javascript help plz

Posted 14 Mar 2007 20:03:44
1
has voted
14 Mar 2007 20:03:44 Alex Chevchenko posted:
i have a form and its funcrions are in javascript and its in the <script> tag on my page i would like to know how to take that code into a different page and link it to the pages where i have my form kinda like the way you link css i would like to do the same thing......in dreamweaver

Replies

Replied 15 Mar 2007 15:33:04
15 Mar 2007 15:33:04 Lee Diggins replied:
Hi Alex

Use the src attribute in the script tag.

1. Move your javascript code into a text file with a js extension and save the file. DO NOT include the script tags.
2. Add the src attribute to script tag in your web page and point it to the new file you've created.

I've examples below of the html file and the js file

<pre id=code><font face=courier size=2 id=code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;script language="JavaScript" type="text/JavaScript" src="scripts/functions.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body &gt;
&lt;a href="#" onClick="click_test();"&gt;Click Me!&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt; </font id=code></pre id=code>

The html file is calling a file called functions.js in a folder called scripts:

<pre id=code><font face=courier size=2 id=code>// JavaScript Document
function click_test(){
alert('Hello World!');
} </font id=code></pre id=code>

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 15 Mar 2007 18:08:33
15 Mar 2007 18:08:33 Lee Diggins replied:
<pre id=code><font face=courier size=2 id=code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;script language="JavaScript" type="text/JavaScript" src="scripts/functions.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body &gt;
&lt;p&gt;&lt;a href="#" onClick="click_test();"&gt;Click Me!&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="#" onClick="navigate_url();"&gt;Navigate to website&lt;/a&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt; </font id=code></pre id=code>

<pre id=code><font face=courier size=2 id=code>// JavaScript Document
function click_test(){
alert('Hello World!');
}

function navigate_url(){
window.location = 'www.microsoft.com';
} </font id=code></pre id=code>

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 15 Mar 2007 18:25:34
15 Mar 2007 18:25:34 Alex Chevchenko replied:
thats the one for the hyperlink?
Replied 15 Mar 2007 18:36:58
15 Mar 2007 18:36:58 Lee Diggins replied:
Yes, I just expanded on the previous example.

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>

Reply to this topic