tags:

views:

54

answers:

3

Hey guys,

One of my pages is becoming overcrowded with html forms and js. So I was wondering if there is a way to have the form on one page and then the js on another. If you could refer me to a good site that addresses this I would really appreciate it.

Thanks

+6  A: 

There is an excellent way. You put your JavaScript in a file, say /scripts/someStuff.js off of your web root, and import it using

<script type="text/javascript" src="/scripts/someStuff.js"></script>
chaos
would this be able to listen to the changes on the form such are checked boxes and then hide elements?
Yup.
chaos
excellent let me give this a try
oh, and do I need a <form action="somestuff.js">?
You guys make life look easy, thanks a bunch
A: 

In JavaScript you can reference objects in another window, if openen with the window.open method. References take the form:

window.opener.form.fieldname.value

dutch
A: 

I am giving you a test example for that I have a external js file named test.js that i have kept in Script folder in my root directory I have button on my page and on its click event client side code is written in test.js file

Main page code

<html>
<head id="Head1">
    <title></title>
    <script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
    <script src="Scripts/test.js" type="text/javascript"></script>
 </head>
<body>
    <input id="TestButton" type="button" value="Test" />
</body>
</html>

External js code in Test.js file

$(function()
{
    $('#TestButton').click(function()
    {
     alert('I am clicked.');
    });

});
Raghav Khunger