I want to get user inputs using the tag in HTML and not the prompt function in JavaScript.
I also don't want to have 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 a .asp
In JavaScript, we use the prompt() function to ask the user for input. As a parameter, we input the text we want to display to the user. Once the user presses “ok,” the input value is returned. We typically store user input in a variable so that we can use the information in our program.
However, what is not understandable is using JavaScript which runs only the browser, to get input from a systems command line. Doing this is possible using NodeJS. It will require us to use the readline() package. With this package, we can then accept user input and even output it to the console.
The <form> tag is used to get user input, by adding the form elements. Different types of form elements include text input, radio button input, submit button, etc.
Create an input
tag with id
attribute
<input type="text" id="a" name="b" />
in javascript, you can get the value of an input
field via its id
var x = document.getElementById('a').value;
<input type="text" id="input1" />
<button onclick="myJsFunction()"></button>
<script type="text/javascript">
function myJsFunction(){
var text=document.getElementById('input1').value;
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With