+ 4
How to link JS function with HTML?
I am always struggling with linking JS function with html ! could you guys please help me to link my awesome money converter? :) <body> <input type="text" id="EUR" value=""> <button oneclick="con()"> Get result</button> <script src="main.js"></script> <div id="msg"> </div> </body> function con(){ "use strict"; var amount = document.getElementById("EUR").value, result = amount * 1.1165, msg = document.getElementById("msg"); } con();
3 Respuestas
+ 5
Try this bro 😇
<input type="text" id="EUR">
<button onclick="con()">Get Result</button>
<div id="msg"></div>
<script>
function con(){
let result = EUR.value * 1.1165;
msg.innerText = result;
}
</script>
+ 5
@Farry I tried whole code over and over !! still doesn't show results
<input type="text" id="EUR" value="">
<button oneclick="con()"> Get result</button>
<script src="main.js"></script>
<div id="msg"> </div>
function con(){
"use strict";
var amount = document.getElementById("EUR").value,
result = amount * 1.1165,
msg = document.getElementById("msg");
}
con();
+ 2
add an onclick listener to the button and enclose the js code between script tags