I have some Javascript that should only display the record from a file if the input field matches with one of the record fields:
<head>
<script src="cswr.js"></script>
</head>
Intensity: <input type="text" name="intensity" id="intensity" list="intensitylist">
<datalist id="intensitylist">
<option value="Heavy">
<option value="Medium">
<option value="Light">
</datalist>
<script>
document.getElementById("intensity").addEventListener("onchange", location.reload.bind(location));
i = 1;
document.writeln("<table>");
for (var c in cswr) {
if (document.getElementById("intensity").value === cswr[c][1]) {
document.write("<tr><td>" + i++ + "</td><td><ul><li>Occurrence: " + c + "</li><li>Rating: " + cswr[c][0] + "</li>");
if (typeof cswr[c][1] != 'undefined') document.write("<li>Intensity: " + cswr[c][1] + "</li>");
document.writeln("</ul></td></tr>");
}
}
document.writeln("</table>");
</script>
The cswr.js file is as follows:
var cswr = {};
cswr['A'] = [5, 'Medium'];
cswr['B'] = [9, 'Medium'];
cswr['C'] = [8, 'Heavy'];
cswr['D'] = [7, 'Heavy'];
cswr['E'] = [7, 'Medium'];
cswr['G'] = [6, 'Light'];
cswr['H'] = [6];
I am looking to refresh the page upon change of the input field, but the user has to press Refresh in the browser for the changes to take effect. How do I change the code so that the page displays the relevant records for when the field loses focus or when the user presses Return?
Note: not too concerned about doctypes, well-formedness, input validation and the such.