Skip to content
Advertisement

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>

Advertisement

Answer

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);
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement