Get userinput in JavaScript

I want to get user inputs using a tag in HTML, and not a prompt function in JavaScript.

I also don't want to use another language on top of this, like php.

Edit Something like this would be desirable

<form action="demo_form.asp"> First name: <input type="text" name="fname"><br> <input type="submit" value="Submit"> </form> 

but without using .asp

+7
javascript html input
source share
4 answers
 <input type="text" id="input1" /> <button onclick="myJsFunction()"></button> <script type="text/javascript"> function myJsFunction(){ var text=document.getElementById('input1').value; } </script> 
+17
source share

Create an input tag with id attribute

 <input type="text" id="a" name="b" /> 

in javascript you can get the value of the input field through its id

 var x = document.getElementById('a').value; 
+3
source share

JavaScript has three types of pop-ups: the Warning, Confirm, and Prompt fields.

 <!DOCTYPE html> <html> <body> <p>Click the button to display an alert box.</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { alert("I am an alert box!"); } </script> </body> </html> 
-one
source share

and for the text box

 <!DOCTYPE html> <html> <body> <p>Click the button to demonstrate the prompt box.</p> <button onclick="myFunction()">Press me</button> <p id="demo"></p> <script> function myFunction() { var x; var person=prompt("Please enter your name","Safa Alrawi"); if (person!=null) { x="Hello " + person + "! How are you today?"; document.getElementById("demo").innerHTML=x; } } </script> </body> </html> 
-one
source share

All Articles