View Single Post
Old Jan 9th, 2007, 2:24 PM   #1
cabdirazzaq
Newbie
 
Join Date: Jan 2007
Posts: 5
Rep Power: 0 cabdirazzaq is on a distinguished road
How to add new items in my script?

Let's see if you can help me manage this one... I have this script to help one memorize things. The thing is, I want the user to be able to add their own items/words into the list (not me doing it before hand). Here is the script:
Quote:
<html>
<head>
<title>Memory tool v.1.0</title>
<script language="Javascript">
var Dictionary = new Array;
var WordsPerPass = 0;
var CurrentWords = '';
function Populate()
{
Dictionary[0] = "Cat";
Dictionary[1] = "Dog";
Dictionary[2] = "Mouse";
Dictionary[3] = "Platypus";
Dictionary[4] = "C";
Dictionary[5] = "Programming";
Dictionary[6] = "Is";
Dictionary[7] = "Fun";
Dictionary[8] = "Yes";
WordsPerPass = 4;
ResetForm();
}
function FillWords()
{
if(CurrentWords != '')
return;
var WordCount = 0;
while(true)
{
var Rand = Math.random();
Rand = Math.round(Rand * (Dictionary.length - 1));
if(CurrentWords.search(Dictionary[Rand]) != -1)
continue;
else
{
CurrentWords += Dictionary[Rand] + ' ';
WordCount++;
if(WordCount == WordsPerPass)
break;
}
}
document.getElementById("Words").value = CurrentWords.replace(/ /g, '\n');
document.getElementById("StartButton").disabled = true;
setTimeout("EraseWords()", document.getElementById("TimeInMinutes").value * 100000);
}
function EraseWords()
{
document.getElementById("Words").value = '';
document.getElementById("StartButton").style.display = 'none';
document.getElementById("StopButton").style.display = 'inline';
}
function CompareWords()
{
var Answer = document.getElementById("Words").value;
var WordsCheckedCount = 0;
var Response = '';
while(true)
{
var Word = Answer.match(/\b.+?\b/);
if(Word == null)
break;
if(CurrentWords.match(Word) == null)
{
Response += 'Incorrect: '+Word+'\n';
}
else
{
Response += 'Correct: '+Word+'\n';
}
Answer = Answer.replace(Word, '');
WordsCheckedCount++;
if(WordsCheckedCount == WordsPerPass)
break;
}
document.getElementById("Words").value = Response + '\n\nAnswers: \n'+CurrentWords.replace(/ /g, '\n');
document.getElementById("StopButton").style.display = 'none';
document.getElementById("ResetButton").style.display = 'inline';
}
function ResetForm()
{
document.getElementById("Words").value = 'Click Start To Begin';
document.getElementById("StartButton").style.display = 'inline';
document.getElementById("StartButton").disabled = false;
document.getElementById("ResetButton").style.display = 'none';
CurrentWords = '';
WordCount = 0;
}
</script>
</head>
<body onLoad="Populate()">
<textarea cols="40" rows="20" id="Words"></textarea>
<select id="TimeInMinutes">
<option value="0.01"> Short</option>
<option value="0.5"> 30 Seconds</option>

<option value="1"> 1 Minute</option>
<option value="2"> 2 Minutes</option>
<option value="3"> 3 Minutes</option>
</select>
<input style="display:inline" type="button" id="StartButton" value="Start" OnClick="FillWords()"/>
<input style="display:none" type="button" id="StopButton" value="Compare", onClick="CompareWords()"/>
<input style="display:none" type="button" id="ResetButton" value="Start Over" onClick="ResetForm()"/>
</body>
</html>
Please, if you could because I really need some help on this one :o

Last edited by big_k105; Jan 9th, 2007 at 4:53 PM.
cabdirazzaq is offline   Reply With Quote