Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 946
EncryptEx Avatar asked Jul 29 '18 08:07

EncryptEx


2 Answers

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);
like image 105
baao Avatar answered Oct 01 '22 06:10

baao


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.

like image 29
Ioannis Papadopoulos Avatar answered Oct 01 '22 07:10

Ioannis Papadopoulos