Reputation: 107
I'm creating a simple messaging system (for learning purposes) where a user enters their passcode or creates one if they don't have one and our message correspondence is stored in an array within another array. Example: you're the 5th user to register, your passcode is the the 5th item in the pass array, and our correspondence is the the 5th array in the logNum array.
I'm wondering if I can use local storage so users can close their browser and still have our correspondence saved and how I would be able to modify the log. But as of now my confirmation paragraph at the bottom is not even being inserted into the document.
I GREATLY appreciate any advice.
<!DOCTYPE HTML>
<html>
<head>
<title>waGwan?</title>
<meta charset="utf-8"/>
<link rel=stylesheet href=comm.css></link>
</head>
<body>
<section>
<p>enter or create passcode: <input type=text id=passcode></p>
<input type=button id="button" value="send">
</section>
<section id="log"></section>
<script type="text/javascript">
var pass[];
var logNum=[];
document.getElementById("button").onclick=checkPass;
function checkPass(){
for(i=0;i<pass.length;i++){
//if passcode already exists exit
if(document.getElementById("passcode").value==pass[i]){
break;
}
//if passcode doesn't equal last existing passcode the passcode is added to the pass array and an array with name passcode is added to the logNum array
else if(document.getElementById("passcode").value!==pass[pass.length-1]){
pass.push(document.getElementById("passcode").value)
logNum.push(var document.getElementById("passcode").value.toString()[]);
}
}
//adds "Works!" to document
document.getElementById("log").innerHTML="<p>Works!</p>";
}
</script>
</body>
</html>
Upvotes: 0
Views: 74
Reputation: 15070
Some typo's ;)
<!DOCTYPE HTML>
<html>
<head>
<title>waGwan?</title>
<meta charset="utf-8"/>
<link rel=stylesheet href=comm.css></link>
</head>
<body>
<section>
<p>enter or create passcode: <input type=text id=passcode></p>
<input type=button id="button" value="send">
</section>
<section id="log"></section>
<script type="text/javascript">
var pass=[]; << here
var logNum=[];
document.getElementById("button").onclick=checkPass;
function checkPass(){
for(i=0;i<pass.length;i++){
//checking if passcode already exists
if(document.getElementById("passcode").value==pass[i]){
break;
}
//if passcode doesn't equal last existing passcode the passcode is added to the pass array and an array with name passcode is added to the logNum array
else if(document.getElementById("passcode").value!==pass[pass.length-1]){
pass.push(document.getElementById("passcode").value)
logNum.push(document.getElementById("passcode").value.toString());<< here
}
}
//adds "Works!" to document
document.getElementById("log").innerHTML="<p>Works!</p>";
}
</script>
</body>
</html>
var pass = [];
logNum.push(document.getElementById("passcode").value.toString());
Working jsfiddle
Try using Firebug for FireFox or another developerstool available for your browser.
Upvotes: 3