EncryptEx
EncryptEx

Reputation: 471

How can I put an input in the alert() box?

I have a question that I want to put an input in an alert box. What thing I have to do to create this? To make it I've to put an another tag, attrib, special properities, etc... Thanks. I think could be like this:

<!DOCTYPE html>
<html>
<head>
	<title>example</title>
</head>
<body>
	<script type="text/javascript">
		alert("<input></input>");
	</script>
</body>
</html>

Upvotes: 37

Views: 106626

Answers (4)

MSA
MSA

Reputation: 277

window object comes with three methods for showing user dialog boxes

this methods will halt current executing program till user provide any response to this box

window.prompt(text, defaultText)

this will take value from user for further process

window.alert(message)

this will only alert user for his action.

window.confirm(message)

this will take user response in boolean form for further process

Upvotes: 6

Ioannis Papadopoulos
Ioannis Papadopoulos

Reputation: 135

You can use

var resp = window.prompt("Your question")

window.prompt is a blocking method (like alert). The program execution will halt until the user enters a value.

Upvotes: 4

Hello World
Hello World

Reputation: 2907

Just use var value = prompt('Your Question');

Upvotes: 3

baao
baao

Reputation: 73241

You can't put anything in an alert box. As the name indicates, it's an alert. You might be looking for a prompt which has an input text field, or confirm to get a true / false depending on user selection.

let foo = prompt('Type here');
let bar = confirm('Confirm or deny');
console.log(foo, bar);

Upvotes: 61

Related Questions