/*----- for an external JavaScript, you DON'T have to put it inside any element or tag... -----*/ /*----- signature: sayMagicWord: void -> void purpose: expects nothing and returns nothing, but has the side effect of causing a pop-up saying PLEASE to appear (if the browser allows it), customizing based on the value in a textfield whose id="enteredName" adapted from course text, p. 235-238 adapted by: Sharon Tuttle last modified: 2016-04-10 -----*/ function sayMagicWord() { // get objects representing the entererName textfield // and latest paragraph elements // 328 coding standard: use var when you begin using // a new variable name var nameField = document.getElementById("enteredName"); var latestPara = document.getElementById("latest"); // I can access the value attribute of the text field // nameField by looking at its value data field if (nameField.value === "") { // alert is a JavaScript function creating a // pop up alert window alert("PLEASE to unknown person!"); // and this actually sets the contents of the // latestPara paragraph element latestPara.innerHTML = "PLEASE to unknown person!"; } else { alert("PLEASE to " + nameField.value); // how validate this? user CAN enter executable content! // ...but is it cross-site scripting if they // affect just their own current page...? 8-/ latestPara.innerHTML = "PLEASE to " + nameField.value; } }