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

Discussion in 'HTML and CSS' started by MrQ-Zard, Mar 31, 2020.

  1. MrQ-Zard

    MrQ-Zard

    Joined:
    Mar 31, 2020
    Messages:
    1
    Likes Received:
    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:
     
    MrQ-Zard, Mar 31, 2020
    #1
    1. Advertisements

  2. MrQ-Zard

    sunfighter

    Joined:
    Nov 27, 2019
    Messages:
    115
    Likes Received:
    16
    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()"
     
    sunfighter, Apr 1, 2020
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.