Uran
Uran

Reputation:

JQuery html on a different pages

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

Upvotes: 0

Views: 98

Answers (3)

Raghav
Raghav

Reputation: 9630

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"></script>
    <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.');
    });

});

Upvotes: 0

dutch
dutch

Reputation: 212

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

Upvotes: 0

chaos
chaos

Reputation: 124297

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>

Upvotes: 6

Related Questions