Reputation: 45
I am trying to take input from an alert, but when I try to assign it, it gives me a button alert.
x = alert('Enter: ');
alert(x);
<!DOCTYPE html>
<html>
</html>
Upvotes: 1
Views: 105
Reputation: 961
alert
doesn't allow for input, but prompt
does.
var username = prompt("Enter name", "");
if (username != null) {
alert("Welcome " + username + "!");
}
Upvotes: 0
Reputation: 19264
Use prompt
instead of alert
in your code.
Syntax:
window.prompt("sometext","defaultText");
x = prompt("Enter text")
alert(x);
<!DOCTYPE html>
<html>
</html>
Also, try a google search (e.g. "alert input") and the first option will give you your answer.
Upvotes: 5