Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
73
rated 0 times [  78] [ 5]  / answers: 1 / hits: 37460  / 9 Years ago, mon, august 24, 2015, 12:00:00

I have this code placed in index.html, all together - Javascript and HTML. what I want is to place the JS into another, separate file called pw.js.



I have created a blank JS file located in folder js. I have added it to (head) as well like this <script src=js/pw.js></script>



This is what I have now in index.html, how to place the JS separatly? Please be specific in answers, I'm a beginner.



<script type=text/javascript>
function isValid(){
var password = document.getElementById('password').value;
if (password == 123)
top.location.href=./file.pdf;
else
{window.location.reload();}
}
</script>

<div class=field_pw>
<form name=PasswordField action=>
Password:
<input type=password id=password name=password class=noborder style=font-size: 25px>
<input type=button class=button_pw value=download onclick=isValid();>
</form>
</div>

More From » html

 Answers
6

your pw.js file in js folder:



function isValid() {
var password = document.getElementById('password').value;
if (password == 123)
top.location.href=./file.pdf;
else
window.location.reload();
}


your html file:



<script type=text/javascript src=js/pw.js></script>
<div class=field_pw>
<form name=PasswordField action=>
Password:
<input type=password id=password name=password class=noborder style=font-size: 25px>
<input type=button class=button_pw value=download onclick=isValid();>
</form>
</div>



[#65308] Friday, August 21, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrence

Total Points: 120
Total Questions: 115
Total Answers: 87

Location: England
Member since Fri, May 22, 2020
4 Years ago
terrence questions
Sat, Jun 5, 21, 00:00, 3 Years ago
Wed, Jun 17, 20, 00:00, 4 Years ago
;