html - Trigger javascript action on click? -
i want trigger javascript code when button clicked. want when button clicked console.log() triggered. attempt:
corel.html :
<!doctype html> <html> <head> <title>corelation</title> <script src="jquery-1.11.3.min.js"></script> <script type="text/javascript" src="corel.js"></script> </head> <body> <form id="tablevar"> variable 1: <input type="text" id="var1"><br> variable 2: <input type="text" id="var2"><br> <button onclick="myfunction()">click me</button> <!-- type button not refresh --> </form> </body> </html>
corel.js :
console.log("iniating app ..."); function myfunction() { console.log('yeah'); }
i not understand not work ?
the button making form submit hence need use preventdefault()
use code,
html
<!doctype html> <html> <head> <title>corelation</title> <script src="jquery-1.11.3.min.js"></script> <script type="text/javascript" src="corel.js"></script> </head> <body> <form id="tablevar"> variable 1: <input type="text" id="var1"><br> variable 2: <input type="text" id="var2"><br> <button onclick="myfunction(event)">click me</button> <!-- type button not refresh --> </form> </body> </html>
corel.js
console.log("iniating app ..."); function myfunction(event) { console.log('yeah'); event.preventdefault(); }
Comments
Post a Comment