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 ?
onclick is not a function" error occurs, because there is no onclick() function in jQuery. To solve the error, use the click function instead, e.g. $('#btn'). click(function () {} . Copied!
The Javascript ReferenceError occurs when referencing a variable that does not exist or has not yet been initialized in the current scope. Reference errors in Javascript are of a few different types, with variations of each, that may get triggered in code.
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">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With