0

My javascript file(test.js) has Method1() method defined.

<script src="../Scripts/test.js" type="text/javascript"></script>

My html is defined as below. I get Method1() not found. Any ideas?

<p><input type="button" name="login" id="login" value="Login" onclick="Method1()"/> </p>

Here is the code in test.js declared...

<script type="text/javascript">

 function LoginToServer() {

......
}

</script>    
2
  • 6
    So... how about showing us test.js? Commented May 19, 2012 at 0:22
  • U are talking about method or function.. if it's method then you should call it by creating instance of the class... Commented May 19, 2012 at 0:24

2 Answers 2

2

The code in .js file is a JavaScript code, not HTML markup.

This:

<script type="text/javascript">
</script>

is HTML markup, not a JavaScript code. You should remove that from test.js.

As you didn't show us exactly how your Method1 is defined, I'll assume it is ok and this is the only error.

Sign up to request clarification or add additional context in comments.

Comments

0

The reason Method1() isn't detected is because your test.js has a syntax error - the <script></script> tags.

Remove the opening and closing <script> tags from your test.js and everything should work properly.

function LoginToServer() {
//function code
}

.js files should only contain JavaScript code.

.html files may also contain JavaScript, but then the code has to be surrounded by <script></script>.

Also, you don't have to provide the type="text/javascript" because HTML5 knows it is going to be JavaScript in-between those tags.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.