The onclick in the code below is not firing the alert correctly.
Here is my code:
function alert_phrase(id){
var value = document.getElementById(id).value;
alert(value);
}
<div id="exp" style="background-color: white;">
<p id="content-exp" style="color: red;">HELLO WORLD!</p>
<input name="phrase" Placheholder="Enter text here" id="phrase" />
<button onclick='alert_phrase(phrase)'>Alert this sentence</button>
</div>
You're forgetting the quotes on your parameter. Hope this helps
function alert_phrase(id){
var value = document.getElementById(id).value;
alert(value);
}
<div id="exp" style="background-color: white;">
<p id="content-exp" style="color: red;">HELLO WORLD!</p>
<input name="phrase" Placheholder="Enter text here" id="phrase" />
<button onclick='alert_phrase("phrase")'>Alert this sentence</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With