473,395 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

need help with something

I'm a college student, and I'm having trouble with one of my
assignments. We creating a spell checker in javascript that has to
compare a user submitted word (using forms) to a 5 word dictionary. If
the word is spelled correctly, all we have to do is say so. If not, we
have to suggest a word from the dictionary based on the individual
letters of the word, or ask if the user wants to add the word to the
dictionary, which would incrememnt the dictionary to 6 words as long as
the browser remains open.

I'm not asking for anyone to tell me how to do this, nor am I asking
anyone to do it for me. I'm simply asking if someone could look at
what I have so far and tell me what I'm doing wrong. I'm a long way
from being done, as I've just started getting stuff to work for me.
I'm very limited in my javascript ability, as the pre-requisite class
for this one was a joke.

Here's what I have so far. What I'm trying to do is take the word the
user types in the first text box and when they press the submit button,
it shows up in the second text box:

<script type="text/javascript">

function usersubmit (form){
var x = document.submitform.userentry.value;
document.userWord.userWordResult.value = x;
}
-->
</script>
</head>
<body>

<form name=submitform onsubmit="return checkform(this);">
<input type=text name=userentry>
<input type=submit value="Submit" >
</form>

<form name=userWord onsubmit="return usersubmit(this);">
<input type=text name=userWordResult>
</form>

Feb 11 '06 #1
10 1416


The event handler onsubmit on form "submitform" should have the
..value assigmening function and should do it before
returning/submitting the form for processing:

function checkform(form) {
........
var x = document.submitform.userentry.value;
document.userWord.userWordResult.value = x;
form.submit();
}

Dann
Feb 11 '06 #2
Thanks for the help. I was able to get that working, now I'm trying to
compare the word submitted by the user to the Array I created. This
code, while I know it's not quite there yet, keeps giving me a "Form
has no properties" error:

<script type="text/javascript">
<!--
function readText (form) {
var wordList = new Array("their", "calendar", "cemetery",
"recommend", "believe");
i = form.inputbox.value;
var wordUsed = form.inputbox.value;
/*var wordSplit = wordUsed.split("");*/
form.userWordResult.value = "";

if(wordList[i] == wordUsed)
form.userWordResult.value = "Correct";
}

-->
</script>
</head>
<body onLoad="readText()">
<form name="myform" method="GET">
Enter your word: <br />
<input type="text" name="inputbox">
<input type="button" name="button2" Value="Check Spelling"
onClick="readText(this.form)">
<p>Your word is:</p>
<input type="text" name="userWordResult"
onClick="writeText(this.form)">
</form>
Any ideas?

Feb 11 '06 #3
VK

AT*****@gmail.com wrote:
Your form is called "myform", not "form"

// Add here:

var form = document.forms['myform'];

// the rest as it is. I don't agree with the syntacs, but it makes the
trick:
i = form.inputbox.value;
var wordUsed = form.inputbox.value;
/*var wordSplit = wordUsed.split("");*/
form.userWordResult.value = "";

if(wordList[i] == wordUsed)
form.userWordResult.value = "Correct";


Feb 11 '06 #4
Thanks. Now if I could just get it to tell me if the word I entered
was correct or not, I'd be all set.

Thanks again.

Al

Feb 12 '06 #5
OK, I think I see what you're talking about. I tried this, but when I
click on the button, nothing happens:

<script type="text/javascript">
<!--
function readText (form) {
var wordList = new Array("their", "calendar", "cemetery",
"recommend", "believe");
i = form.inputbox.value;
var wordUsed = form.inputbox.value;
/*var form = document.forms['myform'];
var wordSplit = wordUsed.split("");*/
form.userWordResult.value = "";

if(wordList[i] == wordUsed)
document.writeln = "Correct";
}

-->
</script>
</head>
<body>
<form name="form" method="GET">
Enter your word: <br />
<input type="text" name="inputbox">
<input type="button" name="button2" Value="Check Spelling"
onClick="readText(this.form)">
<p>Your word is:</p>
<input type="text" name="userWordResult"
onClick="writeText(this.form)">
</form>

Feb 12 '06 #6
OK, this is what I have so far. Now I just need to get it to check for
instances of ddouble typed letters and imsplaced letters.

<script type="text/javascript">
<!--
function readText (form)
{
var wordList = new Array()
wordList[0] = "their"
wordList[1] = "calendar"
wordList[2] = "cemetery"
wordList[3] = "recommend"
wordList[4] = "believe"
i = form.inputbox.value;
var wordUsed = form.inputbox.value;
var i;

for(i=0;i<wordList.length;i++)
{
if(wordUsed == wordList[i]){
alert('Your word is spelled correctly');
break;
}
else if(wordUsed != wordList[i]){
alert('Your word is NOT spelled correctly');
}
}
//if (wordUsed != wordList)
// user wants to add word to array:
// wordList.push(wordUsed)
wordList.push(wordUsed)
form.arrayObjects.value = (wordList.join(", "));
form.userWordResult.value = i.length + ", " + wordUsed.split("");

}
-->
</script>
</head>
<body>
<form name="form" method="GET">
Enter your word: <br />
<input type="text" name="inputbox">
<input type="button" name="button2" Value="Check Spelling"
onClick="readText(this.form)">
<p>Your word is:</p> <p>
<input type="text" name="userWordResult"
onClick="writeText(this.form)">
</p>
<p>
<textarea name="arrayObjects" cols="60" rows="6"
id="arrayObjects"></textarea>
</p>
<p></p>
<input type="reset" name="Reset" value="Clear All fields" />
</form>

Feb 14 '06 #7
AT*****@gmail.com wrote:
OK, this is what I have so far. Now I just need to get it to check for
instances of ddouble typed letters and imsplaced letters.
To do that, you'll have to work out a good comparison function - do you
have any sort of algorithm worked out yet?

<script type="text/javascript">
<!--
There is no need for comment delimiters, just don't use them.

function readText (form)
{
var wordList = new Array()
wordList[0] = "their"
wordList[1] = "calendar"
wordList[2] = "cemetery"
wordList[3] = "recommend"
wordList[4] = "believe"
i = form.inputbox.value;
Here you give 'i' a value in a global context...

All the above statements should be terminated with semi-colons: they
aren't strictly necessary in the source code but they're preferred.

Check out initializers and array literals:

Object initializer (general case):
<URL:http://devedge-temp.mozilla.org/library/manuals/2000/javascript/1.5/guide/obj.html#1008330>

Array literal (a kind of initializer):
<URL:http://devedge-temp.mozilla.org/library/manuals/2000/javascript/1.5/guide/ident.html#1011655>
var wordUsed = form.inputbox.value;
var i;
Now you declare a local 'i'.


for(i=0;i<wordList.length;i++)
And now set the local 'i' to zero to use it in the for loop. Checkout
the for loop syntax at devedge:

<URL:http://devedge-temp.mozilla.org/library/manuals/2000/javascript/1.5/guide/stmtsov.html#1008347>

{
if(wordUsed == wordList[i]){
alert('Your word is spelled correctly');
break;
}
else if(wordUsed != wordList[i]){
alert('Your word is NOT spelled correctly');
You will tell a user that their word isn't spelled correctly even though
it might match one later in the list?

Your logic should be that you suspect that the word it is incorrectly
spelled only if none of the words match (and don't pester the user with
alerts in the meantime). :-)

}
}
//if (wordUsed != wordList)
// user wants to add word to array:
// wordList.push(wordUsed)
wordList.push(wordUsed)
form.arrayObjects.value = (wordList.join(", "));
form.userWordResult.value = i.length + ", " + wordUsed.split("");
I'll guess that what you are going to do here is: if no matches are
found, ask the user if they'd like to add the word to the list of
allowed words. I don't think you should just add the word without asking.

}
-->
</script>
</head>
<body>
<form name="form" method="GET">
Enter your word: <br />
<input type="text" name="inputbox">
<input type="button" name="button2" Value="Check Spelling"
onClick="readText(this.form)">
<p>Your word is:</p> <p>
<input type="text" name="userWordResult"
onClick="writeText(this.form)">
If you really are writing XHTML, attribute names must be in lower case.
But I suspect you aren't, so drop the XHTML closing tags '/>' for
empty elements.

</p>
<p>
<textarea name="arrayObjects" cols="60" rows="6"
id="arrayObjects"></textarea>
</p>
<p></p>
<input type="reset" name="Reset" value="Clear All fields" />
</form>


Make sure you validate your HTML too, it can make a difference (though
in this case it's just for tidiness). The W3C validator takes either a
URL, file upload or pasted code.

<URL:http://validator.w3.org/>

--
Rob
Feb 14 '06 #8
Awesome! Thanks a lot, I really appreciate the help. I have until
Friday, so I'll let you know how I make out.

Al

Feb 14 '06 #9
By the way, this is what I've done since my last post:

<script type="text/javascript">
<!--
function readText (form)
{
var wordList = new Array()
wordList[0] = "their"
wordList[1] = "calendar"
wordList[2] = "cemetery"
wordList[3] = "recommend"
wordList[4] = "believe"
wordList[5] = ""
i = form.inputbox.value;
var wordUsed = form.inputbox.value;
var i;

for(i=0;i<wordList.length;i++)
{
if(wordUsed == wordList[i])
{
form.wordCompareResult.value = "Your word is spelled
correctly";
break;
}
else if(wordUsed != wordList[i])
{
form.wordCompareResult.value = "Your word is NOT spelled
correctly, or is NOT in the dictionary. To add it to the dictionary,
press the \'Add Word\' button.";
}
}
}
-->
</script>
</head>
<body>
<form name="form" method="GET">
Enter your word: <br />
<input type="text" name="inputbox">
<input type="button" name="button2" value="Check Spelling"
onClick="readText(this.form)">
<input type="submit" name="Submit" value="Add Word"
onclick="wordUsed.join(wordList)" />
<p>
<textarea name="wordCompareResult" cols="60" rows="6"
id="arrayObjects"></textarea>
</p>
<p>
<input type="reset" name="Reset" value="Clear All fields" />
</p>
</form>

Feb 14 '06 #10
Did you ever get this thing working? I'd like to see what you ended up
with. Thanks.

Feb 25 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
5
by: Confused User | last post by:
I am working on device that utilizes a Motorola 68HC16 microcontroller. I am using an old unsupported piece of crap Whitesmith's / Intermetrics / Tasking compiler. The embedded compiler business...
7
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a...
7
by: The Cool Giraffe | last post by:
Please note that i do intend to use a header file. However, i'm not sure if it's really needed or just a convention. Suppose we have the following two files. // Something.h class Something {...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.