I'm not sure if this forum is just for CAL tech issues or not, sorry.
So as a new JS programmer, I am trying to design a simple forum of sorts. My problem is that I want the comments to stay permanently. I am guessing I would do that by using
document.write, but my script relies on more of
getElementById from the fields and
innerHTML. I am just looking for a simple way to
INCORPORATE document.write into my script.
Here's my HTML:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script src="commentwrite.js" type="text/javascript" language="javascript">
</script>
</head>
<body>
<h1>Discussion</h1>
<h2>Strategy</h2>
<div id="talk">
</div>
<br>
<br>
<form action="">
<fieldset>
<legend>Select your code name (if it is not there than contact the webmaster):</legend>
<select name="identity" id="usrnm">
<option value="Bob">Bob</option>
<option value="Joe">Joe</option>
</select>
</fieldset>
<fieldset>
<legend>Enter the secret password</legend>
<input type="password" maxlength="14" id="passwrd">
</fieldset>
<fieldset>
<legend>Enter your comment</legend>
<input type="textarea" rows="6" cols="45" id="comment">
</fieldset>
<input type="button" onClick="writeComments()" value="Submit Comment">
</form>
</body>
</html>
And my script:
Code:
function writeComments() {
var usrnm = document.getElementById("usrnm");
var passwrd = document.getElementById("passwrd");
var cmmnt = document.getElementById("comment");
var username = usrnm.value;
var password = passwrd.value;
var comment = cmmnt.value;
if (password == "password") {
var talk = document.getElementById("talk");
var result = "";
result += talk.innerHTML;
result += "<br>"
result += "<b>" + username + "<\/b> says: \n";
result += "<i>" + comment + "<\/i>";
var output = document.getElementById("talk");
output.innerHTML = result;
} else {
alert("Invalid Password");
}
}
Note that it works except for the above problem.
Thanks.