Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 9th, 2007, 1: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 3:53 PM.
cabdirazzaq is offline   Reply With Quote
Old Jan 9th, 2007, 3:20 PM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
It would help if you used the [code] tags. Then we could see your indentation. Also, why have you multiplied by 100000 to get minutes? It should be 60000.

As for populating your word list, why not have the user enter in some words, then do something like:
dictionary = document.getElementById("userwords").value.split(" ");
Also, I'd advise getting the Prototype library. It really makes Javascript coding a heck of a lot easier.
Arevos is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Backup Script :-) Pizentios Perl 18 Jan 12th, 2006 10:50 AM
Cant call c++ program in cgi script. HELP! BaroN NighT Perl 1 Dec 5th, 2005 9:03 PM
A simple perl script satimis Perl 3 Aug 15th, 2005 9:31 AM
Bash Script Help pelon Bash / Shell Scripting 2 Feb 28th, 2005 3:58 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC