How do i get the response from a prompt window and make it show up somewhere on the webpage?
The code i have right now is:
<html> <head> <center> <FORM> <INPUT type="button" value="Click Me." name="button" onClick="alert('I Like Waffles')"> <INPUT type="button" value="Whats Your Favorite Food" name="button" onClick="prompt('Whats Your Favorite Food?')"> </FORM> </center> </head> </html>
i want to know how to take the response from the prompt and place it somewhere in the html.
Prompt will return the value.
alert(prompt('Whats Your Favorite Food?'))
<html> <head> <center> <FORM> <INPUT type="button" value="Click Me." name="button" onClick="alert('I Like Waffles')"> <INPUT type="button" value="Whats Your Favorite Food" name="button" onClick="alert(prompt('Whats Your Favorite Food?'))"> </FORM> </center> </head> </html>
Working example:
<html>
<head>
<center>
<script>
function gen(){
var a = prompt("What's your favorite food?");
document.getElementById("demo").innerHTML = a;
}
</script>
<FORM>
<INPUT type="button" value="Click Me." name="button" id="button" onClick="alert('I Like Waffles')">
<INPUT type="button" value="Whats Your Favorite Food" name="button" onClick="gen();">
<p id="demo"></p>
</FORM>
</center>
Check out this Fiddle
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.