querySelector querySelectorAll createElement appendChildquerySelector -- Creates a JavaScript object that represents the first element specified by the selector. Selectors can be element selectors (e.g., "input"), id selectors (e.g., "#btn1"), or class selectors (e.g.,"red")
var paraObj = document.createElement("p");
appendChild -- Adds an element to the DOM tree by adding it as the
last child of the parent object, e.g.,olObj.appendChild(liObj);
1. Correct 2. Incorrect 3. CorrectAnswer: add this empty paragraph to the end of the body:
<p id="details"></p>Modify the script.js file to look like this:
function computeScore( ) {
const correctAnswers = ["", "b", "c", "a"];
var numCorrect = 0;
var details = "";
for(var i = 1; i <= 3; i++) {
var isCorrect = false;
for(var j = 1; j <= 3; j++) {
var rb = document.getElementById("" + i + j);
if (rb.checked && rb.value == correctAnswers[i]) {
numCorrect++;
isCorrect = true;
}
}
var word = isCorrect ? "Correct" : "Incorrect";
details += `${i}: ${word} `;
}
var outputPara = document.getElementById("numcorrect");
outputPara.innerHTML = "Number correct: " + numCorrect;
var detailsPara = document.getElementById("details");
detailsPara.innerHTML = details;
}
function init( ) {
var button1 = document.getElementById("btn1");
button1.addEventListener("click", computeScore);
}
window.addEventListener("load", init);
studentweb.cdm.depaul.eduis
216.220.181.34
GET /test.txt http/1.0The response would look something like this:
HTTP/1.1 302 Found Date: Thu, 19 Feb 2021 02:50:55 GMT Server: Apache/2.0.53 HP-UX-Apache-based_Web_Server (Unix) PHP/4.3.8 Last-Modified: Tue, 27 Oct 2015 14:39:09 GMT ETag: "16896-61d-408dd700" Accept-Ranges:Bytes Content-Length: 18 Connection: close Content-Type: text/html Content: This is a test.
PS C:\Users\sjost> Invoke-WebRequest facweb.cdm.depaul.edu/sjost/test.txt
StatusCode : 200
StatusDescription : OK
Content : This is a test.
RawContent : HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 18
Content-Type: text/plain
Date: Fri, 19 Feb 2021 20:50:26 GMT
ETag: "6590583dc510d11:0"
Last-Modified: Tue, 27 Oct 2015 14:39:09 GMT
Serve...
Forms : {}
Headers : {[Accept-Ranges, bytes], [Content-Length, 18],
[Content-Type, text/plain], [Date, Fri,
19 Feb 2021 20:50:26 GMT]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : mshtml.HTMLDocumentClass
RawContentLength : 18
> curl -v http://facweb.cdm.depaul.edu/sjost/test.txtYou should get output something like this:
* Trying 216.220.181.39:80... * TCP_NODELAY set * Connected to facweb.cdm.depaul.edu (216.220.181.39) port 80 (#0) > GET /sjost/test.txt HTTP/1.1 > Host: facweb.cdm.depaul.edu > User-Agent: curl/7.68.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Content-Type: text/plain < Last-Modified: Tue, 27 Oct 2015 14:39:09 GMT < Accept-Ranges: bytes < ETag: "6590583dc510d11:0" < Server: Microsoft-IIS/10.0 < X-Powered-By: ASP.NET < Date: Mon, 02 Oct 2023 00:25:08 GMT < Content-Length: 18
We will discuss this section on Mar 9.
<form action="http://server-site.org/accepting-page.php"
method="get">
// HTML controls go here.
<input type="submit">
</form>
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML Submit Page</title>
</head>
<body>
<h1>HTML Submit Page</h1>
<form action="http://ectweb.cs.depaul.edu/sjost/response-get.php"
method="get">
<label for="fname">First Name</label><br>
<input type="text" id="fname" name="fname"><br><br>
<label for="gender">Gender</label><br>
<input type="text" id="gender" name="gender"><br><br>
<label for="age">Age</label><br>
<input type="text" id="age" name="age"><br><br>
<input type="submit" value="Submit Form">
</form>
</body>
</html>
<input type="text" id="age" name="age">If the name attribute is submitted, this data will not be sent to the server when the form is submitted.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Response Page -- GET</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h2>Response Page -- GET</h2>
<h3>PHP Page</h3>
<p>fname : <?php echo $_GET["fname"]; ?></p>
<p>gender : <?php echo $_GET["gender"]; ?></p>
<p>age : <?php echo $_GET["age"]; ?></p>
</body>
</html>
http://ectweb.cs.depaul.edu/sjost/response-get.php?fname=Steve&gender=M&age=59When the GET method is used for passing parameters, the fields fname, gender, and age are passed to the response page in the URL. Although this is simple, it is a security risk.
<form action="http://ectweb.cs.depaul.edu/sjost/get-response.php" method="post">
We will discuss this section on Mar 9.
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Validating a Form for Presence</h1>
<p>* means required field</p>
<form name="form1"
action="https://ectweb.cs.depaul.edu/sjost/response-get.php"
method="get">
<label for="fname">*First Name:</label><br>
<input type="text" id="fname" name="fname"><br><br>
<label for="gender">Gender:</label><br>
<input type="text" id="gender" name="gender"><br><br>
<label for="age">Age:</label><br>
<input type="text" id="name" name="age"><br><br>
<input type="submit" value="Submit Form">
</form>
</body>
</html>
If the fname field is left blank, we want the submission to be cancelled when
the submit button is clicked. We can accomplish this by adding the following script to the form:
function validateForm(e) {
var x = document.form1.fname.value;
if (x == "") {
alert("Name is a required field.");
// Calling the preventDefault method
// prevents the default behavior of
// the submitting the form when the
// submit button is clicked.
e.preventDefault( );
}
}
function init( ) {
var f = document.getElementsByName("form1");
f[0].addEventListener("submit", validateForm);
}
window.onload = init;
var x = document.form1.fname.value; var x = document.forms["form1"]["fname"].value; var x = document.forms[0][0].value;