call javascript function from html using onclick

Today, We want to share with you call javascript function from html.In this post we will show you calling javascript function, hear for function from html without event we will give you demo and example for implement.In this post, we will learn about html javascript function on load with an example.

calling external javascript function from html

Example 1: javascript function call with variable

function getdata() {
  alert('Welcome To Pakainfo.com');
}

var yourfullFunctionName = 'getdata';

window[yourfullFunctionName]();


Example 2: running a function in a function javascript

function getProductsDetails() {
  getShop();
}

function getShop() {
  alert("getProductsDetails made me run");
}

getProductsDetails();

How to call a JavaScript function within an HTML body?

Example 3: HTML File

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src='myscriptmain.js'> </script>
    <title>abc</title><meta charset="utf-8"/>
</head>
<body>
    <script>
    tryMe('It is me Raghav Mehta Log in');
    </script>
</body>
</html>

js file

function tryMe(arg) {
    document.write(arg);
}

I hope you get an idea about JavaScript Functions.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.