4

I would like to ask a series of question to users in one function using

<input type="text" id="input">

In C, the scanf() function allows you to wait for user response and continue if the user enters a value. In JavaScript, how can I wait for user response in a function without using prompt() ?

R.J. Dunnill
  • 1,874
  • 3
  • 9
  • 20
Minjae Kwak
  • 185
  • 1
  • 2
  • 8

3 Answers3

1

There is default javascript function prompt();

reference

<!DOCTYPE html>
<html>
<body>

<p>Click the button to demonstrate the prompt box.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
    var person = prompt("Please enter your name", "Harry Potter");
    if (person != null) {
        alert( person );
    }
}
</script>

</body>
</html>
Pranav Bhatt
  • 711
  • 4
  • 8
0

You can use onChange in js.

$(document).on('change','#input',function(e){
  e.preventDefault
});
Ritchee
  • 13
  • 3
0

you can use preventDefault() and stopPropagation()

$(document).on('change','#input',function(event){
  event.preventDefault()
  event.stopPropagation()
});
Tenusha Guruge
  • 1,891
  • 2
  • 14
  • 37