Week 12
Task 4user_1373341
html
2 years ago
2.8 kB
14
Indexable
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Question 4</title>
</head>
<body onload="randomValue()">
<h1>Whosville library book search</h1>
<form action="http://library.whosville/bsearch" method="GET" onsubmit="return validation()">
<table border="0">
<tr>
<td>Author name:</td>
<td>
<input type="text" size="33" name="author">
</td>
</tr>
<tr>
<td>Publication year:</td>
<td>
<input type="text" size="33" name="year">
</td>
</tr>
<tr>
<td valign="top">Subject:</td>
<td>
<input type="checkbox" name="sub" value="mth"> Mathematics <br />
<input type="checkbox" name="sub" value="cs"> Computer Science <br />
<input type="checkbox" name="sub" value="bio"> Biology <br />
<input type="checkbox" name="sub" value="phy"> Physics <br />
<input type="checkbox" name="sub" value="chem"> Chemistry
</td>
</tr>
<tr>
<td colspan="2">
<span id="robotCheck"></span>
<input type="text" id="val" size="5">
<span id="message"></span>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Search">
<input type="reset" value="Clear">
</td>
</tr>
</table>
</form>
<script type="text/javascript">
var num1;
var num2;
var sum;
function randomValue() {
num1 = Math.floor(Math.random()*10);
num2 = Math.floor(Math.random()*10);
sum = num1 + num2;
console.log("num1: " + num1 + " num2: " + num2);
var robotCheck = document.getElementById("robotCheck");
robotCheck.innerHTML = "Prove that you are not a robot: " + num1 + " + " + num2 + " = ";
}
function validation() {
var val = parseInt(document.getElementById("val").value);
var message = document.getElementById("message");
if (val != sum) {
message.innerHTML = '<font color="red">Wrong!</font>';
return false;
}
return true;
}
</script>
</body>
</html>Editor is loading...