How can I save user input as a variable in html/JavaScript?

I’m trying to make an html file that asks the user for three numbers then puts the input in separate variables to be used with the code… If anyone knows how please tell me…

did you want something like

<!DOCTYPE html>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>prompt demo</title>
    <h1 id='demo'> </h1>
      var name=prompt('your name please')
      document.getElementById("demo").innerHTML='your name is '+name

Sorry no I meant to change what I said… What I meant was the user inputs three numbers and it gets put into separate variables to be used in the code… Sorry about that

It’s just the example how you can do that :slight_smile:

so same way you can create three variable and ask users for input.

can i see your code what you’ve done so far?


Ok thanks I will try that and I can’t show you my code currently… But I will when I get the chance.:smiley:

1 Like

It worked Thank You:smiley:

1 Like

I m so happy that you solved it :slight_smile:

1 Like

Wait would this be possible in a type of input?

<. Input. Type. =. “text”. >

yes, using <input type='text'> is absolutely possible.

1 Like

How would I do it the code you gave me did not work

you still would need to write the code to make it work, your question was if it was possible. I confirmed that the use of <input type='text'> is possible

well, we would need to make a button to allow the user to submit there entered text, then we would need either onclick attribute on the <input type='button'> to call a javascript function, or add an event listener to the button

once we done this, we can retrieve the input from the field.

This is a lot more complicated then using the prompt() function as you can see

we could use var input = document.getElementById("input_id").value; to get the value of input field, where input_id is the id of your input field.


I took advantage of your mistake because to me this is what I need and its really helpful