I'm just starting out learning HTML/JavaScript. I've got a form that when submitted it should show the input data back to the user, I've tried both an alert and the .html() method and neither seem to display the information back.
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script src="scripts/jquery-3.2.1.js"></script>
<script>
function displayInfo() {
let product = ($('#productName').val());
let quantity = parseInt($('#qty').val());
if ($('#delivery:checked').val() == 'y'){
let delivery = "Delivery required";
}
else{
let delivery = "Delivery not required";
}
var info = "Product name: " + product + "<br>" + "Quantity: " + quantity + "<br>" + "Delivery?:" + delivery;
$("#info").html(info);
}
</script>
</head>
<body>
<h1>Example page</h1>
<form onsubmit="displayInfo(); return false;">
<p>Enter the name of the product you want to buy: <input type="text" id="productName"/></p>
<p>Enter the quantity you want to buy: <input type="text" id="qty" /></p>
<p>Do you require delivery? <input type="checkbox" id="delivery" value="y" /></p>
<p><input type="submit" value="Place order" /></p>
</form>
<div id ="info"></div>
</body>
</html>
and also
alert("Product name: " + product + "<br>" + "Quantity: " + quantity + "<br>" + "Delivery?:" + delivery);