Lowest price ever! Learn Generative AI for 48% less!
Get my discount
+ 3

How do we take imput from user in java script

tell the statements for all the data types

18th Nov 2018, 6:01 AM
Preeti
Preeti - avatar
3 Answers
+ 4
Use prompt("the text","default value")
18th Nov 2018, 7:57 AM
Taste
Taste - avatar
+ 4
Also you can make an <input> element and use document.getElementById(id of it).value
18th Nov 2018, 8:01 AM
Proff
Proff - avatar
+ 2
There are actually two types of input data: 1. string - via HTMLElements or prompt window. You can get any value of every element in the DOM eigther by innerText/innerHTML or from an input element by value. But even if your input type is "number" the type you get is always a string. 2. Object - in form of Events. (keyEvent/mouseEvent...) Events have payload which can be of any JS type. But the payload can not be defined directly by the user. So the only type of input you can get from the user is: string.
18th Nov 2018, 8:11 AM
Andreas
Andreas - avatar