omriman12
omriman12

Reputation: 1690

Running JavaScript specific function from html

Abit new to html and javascript.

I got a JS script and an html code.

I want to run a specific function in my JS form my html code. how do i do that?

My JS generalRedirect.js:

var redirect = {
test1: function () {
    window.alert("sometext");
},
....

My HTML:

..
<script src="@Url.Content(".../Scripts/generalRedirect.js")" type="text/javascript"></script>

Upvotes: 0

Views: 60

Answers (2)

Naveen Chandra Tiwari
Naveen Chandra Tiwari

Reputation: 5123

Try to do something like this:

 <script src='@Url.Content(".../Scripts/generalRedirect.js")' type="text/javascript"></script>
 <script>
     redirect.test1();
</script>

Upvotes: 1

Amit Joki
Amit Joki

Reputation: 59232

I want to run a specific function in my JS form my html code. how do i do that?

You can call your function like this:

redirect.test1();

and don't forget to put that inside <script> tags and also be sure to include the correct file.

Do this:

<script src='@Url.Content(".../Scripts/generalRedirect.js")' type="text/javascript></script>
<script>
  redirect.test1();
</script>

Upvotes: 1

Related Questions