skip to Main Content

HTML file:

<html>

<head>
  <title></title>
  <script lanuage='javascript' ;src="test.js"></script>
</head>

<script language="javascript">
  test1(1, 2);
</script>

<body>
  <p id="t">test page for p server</p>
</body>
</html>

test.js file:

function test1(x, y) {
  var x, y;
  z = x + y
  document.write('z: ', z)
  return (z)
}

error appearing on the browser is Uncaught ReferenceError: test1 is not defined

This error does not come when I have the function inside the .html file. I want to have the function in the linked .js and was wondering how I could resolve this issue.

2

Answers


  1. you can try to change
    test1(1, 2)); with test1(1, 2);

    Login or Signup to reply.
  2. It doesn’t work because ;src is not a valid attribute

    Replace

    <script lanuage='javascript' ;src="test.js"></script>
    

    with

    <script src="test.js"></script>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search