mortalc Posted May 17, 2010 Share Posted May 17, 2010 How can I use a button in Javascript?I just need it to do 2 mathematical operations on click. Link to comment Share on other sites More sharing options...
Synook Posted May 17, 2010 Share Posted May 17, 2010 Set the onclick handler of the "button" (it doesn't have to be a <button>) to run your function. document.getElementById("button").onclick = function() { do_maths();} Link to comment Share on other sites More sharing options...
chibineku Posted May 17, 2010 Share Posted May 17, 2010 Bind the onclick event of the button to a function, which can be done most easily in the button element:<input type="button" onclick="myFunction()" />And then in myFunction() you can do whatever you want to do.Edit: or attach the handler in script as Synook demonstrated, which is considered best practice anyway Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.