Paste this code inside head
tags between script
tags
HTML
<button id="button">Get Text</button>β
Js
window.onload=function() { var el=document.getElementById('button'); el.onclick=function(){ var my_text=prompt('Enter text here'); if(my_text) alert(my_text);
Demo.
source share