How to get user input on java script? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to get user input on java script?

print stmt like document.write()

10th Sep 2017, 2:46 PM
SALIM RAJA M
SALIM RAJA M - avatar
3 Answers
+ 12
var a = prompt("Please enter your name"); alert(a);
10th Sep 2017, 3:07 PM
Ranjan Bagri
Ranjan Bagri - avatar
+ 6
You could use prompt function or use form input and submit <form onsubmit="get(this,event)"> <input type="type" name="i"> <input type="submit"> </form> <script> function get(e,evt){ evt.preventDefault(); alert(e.i.value); } </script> https://code.sololearn.com/WC80ZyBuo47R/?ref=app Don't use document.write(), it would erase the webpage with new write data, unless you intend to do it this way.
10th Sep 2017, 3:23 PM
Calviղ
Calviղ - avatar
+ 4
use prompt("");
10th Sep 2017, 2:59 PM
_Retr0/-
_Retr0/- - avatar