Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
186
rated 0 times [  193] [ 7]  / answers: 1 / hits: 127171  / 7 Years ago, tue, april 4, 2017, 12:00:00

I am trying to call a simple javascript function from my html page. The javascript function will decrypt using the lib.js file and the same is alerted.



Uncaught ReferenceError: decryptfun is not defined
at HTMLInputElement.onclick (test.html:18)



The below is the only file I use (along with other dependent library files).



<!DOCTYPE html>
<html>
<head>
<script type=text/javascript src=lib.js>
function decryptfun() {
var pass = hjubjbjhdgyuwj;
var encrtoken = abcdefghijklmn;

var p = lib.decrypt(encrtoken, atob(pass));
}
alert(p);
</script>
</head>

<body>
<h1>Decrypt Operation</h1>
<input type=button onclick=decryptfun() value=Click>
</body>
</html>


I tried other suggestions provided for the same type of issue at Stackoverflow but I was not successful. Can anybody help me out in locating the cause of the issue ?


More From » javascript

 Answers
3

Your error is because you have defined your function inside:



<script type=text/javascript src=lib.js>


the correct way is to close that script tag first like so:



<script type=text/javascript src=lib.js></script>


and then defining the script tag again to define the function like so:



<script>
function(){
//body of function
};
</script>




<script type=text/javascript src=lib.js></script>
<script>
function decryptfun() {
var pass = hjubjbjhdgyuwj;
var encrtoken = abcdefghijklmn;

//var p = lib.decrypt(encrtoken, atob(pass)); //USE THIS IN YOUR CASE
var p = test; //just for example
alert(p);
}
</script>
<h1>Decrypt Operation</h1>
<input type=button onclick=decryptfun() value=Click>




[#58273] Sunday, April 2, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breap

Total Points: 606
Total Questions: 96
Total Answers: 108

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
;