"Onclick" attribute, to create button in HTML is not working

In the lecture named as “Creating your function in javascript” . i am getting a button on my webpage but that button is not working . i have tried different youtube tutorials regarding this issue but nothing seems to work .
i have added link to button tag using “ahref” attribute and that seems to work fine …but the issue appears when i am using “onclick” to call my function using html button .

the final html webpage shows a button as expected but nothing happens when we click on it.

@sarthakchowdhary711
Could you upload a picture of your program???

the screenshot of html program and its associated javascropt function pragram is attached below

The screenshot of the output of this program is attached below . the button displayed does not perform any action upon clicking .

@sarthakchowdhary711
Hey, ok i think I’ve got your problem hopefully it should work.
The copyjs04 part of it change to,
funct.js
function myFunction(myName) {
** var elem = document.getElementById(“hello”);**
** elem.innerHTML = elem.innerHTML + myName;**
** }**
change to this and save it as a javascript extension.(the first line don’t make it function.js otherwise the sublime application takes it as a function instead of a file name, save it as funct.js only)
the copybutton part of it change to,
5th line - src="funct.js"
Just change the source part, small change.
And that should solve your problem. If it doesn’t I’m sorry i couldn’t help out.
{The HTML file is just to display your content while your JS file does the actual programming work, so the source"src command on 5th line" from where it gets the JS function has to be the exact same name as what you saved the JS file name in .js extension. Eg: If you save the JS file as button.js then in the HTML file your source command should say src=“button.js”}

1 Like

It worked .Thank you.

1 Like

@sarthakchowdhary711
Hey
Welcome, Glad I could help.