473,835 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.submit form.userentry. value;
document.userWo rd.userWordResu lt.value = x;
}
-->
</script>
</head>
<body>

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

<form name=userWord onsubmit="retur n usersubmit(this );">
<input type=text name=userWordRe sult>
</form>

Feb 11 '06 #1
10 1435


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.submit form.userentry. value;
document.userWo rd.userWordResu lt.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.v alue;
var wordUsed = form.inputbox.v alue;
/*var wordSplit = wordUsed.split( "");*/
form.userWordRe sult.value = "";

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

-->
</script>
</head>
<body onLoad="readTex t()">
<form name="myform" method="GET">
Enter your word: <br />
<input type="text" name="inputbox" >
<input type="button" name="button2" Value="Check Spelling"
onClick="readTe xt(this.form)">
<p>Your word is:</p>
<input type="text" name="userWordR esult"
onClick="writeT ext(this.form)" >
</form>
Any ideas?

Feb 11 '06 #3
VK

AT*****@gmail.c om 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.v alue;
var wordUsed = form.inputbox.v alue;
/*var wordSplit = wordUsed.split( "");*/
form.userWordRe sult.value = "";

if(wordList[i] == wordUsed)
form.userWordRe sult.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.v alue;
var wordUsed = form.inputbox.v alue;
/*var form = document.forms['myform'];
var wordSplit = wordUsed.split( "");*/
form.userWordRe sult.value = "";

if(wordList[i] == wordUsed)
document.writel n = "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="readTe xt(this.form)">
<p>Your word is:</p>
<input type="text" name="userWordR esult"
onClick="writeT ext(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.v alue;
var wordUsed = form.inputbox.v alue;
var i;

for(i=0;i<wordL ist.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(w ordUsed)
wordList.push(w ordUsed)
form.arrayObjec ts.value = (wordList.join( ", "));
form.userWordRe sult.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="readTe xt(this.form)">
<p>Your word is:</p> <p>
<input type="text" name="userWordR esult"
onClick="writeT ext(this.form)" >
</p>
<p>
<textarea name="arrayObje cts" cols="60" rows="6"
id="arrayObject s"></textarea>
</p>
<p></p>
<input type="reset" name="Reset" value="Clear All fields" />
</form>

Feb 14 '06 #7
AT*****@gmail.c om 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.v alue;
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.or g/library/manuals/2000/javascript/1.5/guide/obj.html#100833 0>

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


for(i=0;i<wordL ist.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.or g/library/manuals/2000/javascript/1.5/guide/stmtsov.html#10 08347>

{
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(w ordUsed)
wordList.push(w ordUsed)
form.arrayObjec ts.value = (wordList.join( ", "));
form.userWordRe sult.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="readTe xt(this.form)">
<p>Your word is:</p> <p>
<input type="text" name="userWordR esult"
onClick="writeT ext(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="arrayObje cts" cols="60" rows="6"
id="arrayObject s"></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.or g/>

--
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.v alue;
var wordUsed = form.inputbox.v alue;
var i;

for(i=0;i<wordL ist.length;i++)
{
if(wordUsed == wordList[i])
{
form.wordCompar eResult.value = "Your word is spelled
correctly";
break;
}
else if(wordUsed != wordList[i])
{
form.wordCompar eResult.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="readTe xt(this.form)">
<input type="submit" name="Submit" value="Add Word"
onclick="wordUs ed.join(wordLis t)" />
<p>
<textarea name="wordCompa reResult" cols="60" rows="6"
id="arrayObject s"></textarea>
</p>
<p>
<input type="reset" name="Reset" value="Clear All fields" />
</p>
</form>

Feb 14 '06 #10

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

Similar topics

7
4394
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 few features that you'd expect in any editor, except nearly none of them seem to have: 1 - Search and repalce with Regular Expressions. 2 - Search and Replace in an Xpath context. 3 - User specified tag-generation for either on a...
19
4119
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 the code that implements managing unbound controls on forms given the superior performance of unbound controls in a client/server environment. I can easily understand a newbie using bound controls or someone with a tight deadline. I guess I need...
5
4413
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 was quite insestual for while wasn't it? I need to write putchar so that printf can function properly. Anyway, the compiler comes with just a shell of a putchar routine. It literally returns the character you passed to it and nothing else. That is...
7
2362
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 WinForms interface and then need to port that to a web app. I am kinda stuck on a design issue and need some suggestions / direction. Basically I have a business layer that I want to use to process any dataentry logic (row focus changes, data...
7
2251
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 { private: int number; public: Something ();
0
9810
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10524
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10562
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10236
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7768
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5639
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3997
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3092
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.