How can I create a button that runs a line of javascript code?


Joined
Mar 31, 2020
Messages
1
Reaction score
0
I'm working on a school project, and I need a way to link my JavaScript (file: script.js) to an html5 button. I am using repl.it for the project. Somebody please help me! :eek:
 
Ad

Advertisements

Joined
Nov 27, 2019
Messages
127
Reaction score
19
I am using repl.it for the project.
You do know that a browser and notepad work, if you don't program in PHP, and are free. Also free is notepad++ and VScode for editors?

Three ways to run JS from a button. But for beginners I'd suggest the onclick attribute. Lets say your JS code is in a function named myJavaScript. Then the button attr. would be onclick="myJavaScript()"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top