Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 166
Registered: ‎02-15-2012
My Device: Playbook 16GB
My Carrier: Bags are useful

Splitting and Checking against Javascript array

Hi everyone,

 

Im struggling with what steps to take even in my algorithm to solve my problem. Here is what I have done so far:

 

1. I have a text box (form) with the id "message"

 

2.Im then using this

 

document.getElementById ('message');

 

to store that value in the variable called "words"

 

3.I have then made a new variable straight after:

 

splitwords = words.split(" ") 

 

So the message: "Hello world my name is flow"

 

should now be stored like this

 

splitwords[0] = "Hello"

splitwords[1] = "world"

splitwords[3] = "my"

etc...

 

First of all am I even doing this correctly?

And if Im not someone help me with how I should tackle the problem is there is one so far.

 

So here is the actual problem:

 

I have an array of 10 words. I want to compare all of the splitwords with each word in the array so if thre is a match I can output the words that match. E.g:

 

If my array contains the words "hello" and splitword[x] contains the words "hello" then the output should be:

Match has been found: Hello

 

Any help is greatly appreciated,

If you want me to explain more clearly then please ask me to :smileyhappy:

 

Regards,

Flow

 

 

 

 

 

If any post helps you please click the Like Button below the post(s) that helped you.
2. Please resolve your thread by marking the post "Solution?" which solved it for you!

Developer
Posts: 466
Registered: ‎04-11-2012
My Device: Bold 9900
My Carrier: Rogers

Re: Splitting and Checking against Javascript array

2 ways to check if you got the right words in your variables

easy and painful : put an alert function in

less easy and less painful : put in a text area and have your text output there

PS take note of the overflow you may have if you have 3 words in your string and you try splitwords[3] will return with an error.

Developer for easyDial for BlackBerry Bold & inLink for BlackBerry PlayBook
Find me online via twitter, or on the techfruits.com webpage. Please hit the like button below if what I said helped!