+ 2

How do I get a input from user in JS

For example if I have to make a program in which I will use input from the user for his age and then the output wil be if he has voting right or not

22nd Jul 2020, 10:52 AM
Raghu Rao
Raghu Rao - avatar
4 Answers
+ 4
Thanks
22nd Jul 2020, 10:55 AM
Raghu Rao
Raghu Rao - avatar
+ 2
Alert, prompt and confirm dialog mainly for debugging purposes. For html/JavaScript web application, inputs from users are obtained from form and input elements. Output message would be displayed dynamically on other html elements Here an example: <body> <form onsubmit="checkAge(event)"> <input type="number" id="age" min="0" max="150" value="18" /> <input type="submit" value="Check voting right" /> </form> <p id="message"></p> <script> function checkAge(e) { e.preventDefault(); var age = e.target.age.value; var message = document.getElementById("message"); if(age >= 18) { message.innerText = "You have voting right"; } else { message.innerText = "You do not have voting right"; } } </script> </body> https://code.sololearn.com/Wz7j820H0nPM/?ref=app
22nd Jul 2020, 11:06 AM
CalviŐČ
CalviŐČ - avatar
+ 2
Thank you
22nd Jul 2020, 2:55 PM
Raghu Rao
Raghu Rao - avatar
+ 1
Prompt
25th Jul 2020, 5:22 AM
Raghu Rao
Raghu Rao - avatar