[Solved] use html button to call javascript function [closed]


I don’t fully understand your question, but I’m guessing you want your solve() function to execute when a button is pressed. Here are three options:

window.onload = function() {

    var button = document.getElementById("button");

    // Method 1

    button.addEventListener("click", function() {
        alert("clicked1");
        solve(a, b, c);
        // ^ Insert Params ^ 
    });

    // Method 2

    button.onclick = function() {
        alert("clicked2");
        solve(a, b, c);
        // ^ Insert Params ^
    };
    
};
#button {
    width: 100px;
    height: 100px;
    background-color: green;
}
<!DOCTYPE html>
<html>
    <head>
    
    </head>
    <body>
        <div id="button"> <p>This is a button</p></div>
    </body>
</html>

I hope this solves your question.

2

solved use html button to call javascript function [closed]