Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
why doesn't html file connect with javascript file?

I have a problem guys. Trying to write HTML and JS code in different files and connect them. I think I have done it, but nothing works. How it must be done? (javascript file name is correct)

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="index.js">
    <title>Document</title>
</head>

<body>
    <h3>Check password size</h3>
   <div class="checker">
     <input type="password" name="passcode" placeholder="Enter password" ><br><br>
     <input type="submit" value="check my password!" onclick="checkpassword()">
   </div>
<p id="message" class="message"></p>
</body>
</html>

JAVASCRIPT

function checkpassword(){
    var pas=document.getElementsByName('passcode')[0].value;
    var x=pas.length;
    document.getElementById("message").innerHTML="Password size is" +" " +x +" " +"characters";
}
about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

You sould use the following line to call for/import your javascript.

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

The way you are writing the code is only to call for a css file. To call for a different language, you use a different code.

about 4 years ago · Santiago Gelvez Report

0

<script src="fileName.js"></script>

This is used to connect js to html src means source One more way to do js in html is by using in html and writing your code in the tag like

<script>
function checkpassword(){
var pas=document.getElementsByName('passcode')[0].value;
var x=pas.length;
document.getElementById("message").innerHTML="Password size is" +" " 
+x +" " +"characters";
}
</script>

you can put this code in html or can make seprate files

hope it helped you :)

about 4 years ago · Santiago Gelvez Report

0

You need to use the script tag to connect javascript with html

<script src="yourFile.js"></script>
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!