Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop thorugh words in Textbox entry

Status
Not open for further replies.
Sep 27, 2001
179
AU
Hi

Can you give me some idea how I can approach the following:

I want to write a script that will take the input from a textbox, loop through each word to evaluate it. It will look for know abbreviations and convert to the full word. It will then replace the entry with an updated string.

I know that I will have to use regular expressions to ensure it doesn't count spaces as words, and a Switch statement to evaluate each word against a list of abbreviations. But just need some ideas of the structure.

Thanks

Rob

Robert Colborne
----------------------------
Certified GoldMine, AccPac CRM and SuperOffice consultant
 
you might want to start by splitting your input string on spaces using .split() and then you will have an array containing each individual word that can be lopped through...after checking for abbreviations, you will be able to put the array back into a string using .join()

var myString = document.myForm.txtBoxID.value
var wordArray = myString.split(" ")

for (var i=0;i<wordArray.length;i++) {
//evaluate word and replace if necessary
}

myString = wordArray.join(" ")
 
Thanks, that was helpful...managed to get the code working well.


Robert Colborne
----------------------------
Certified GoldMine, AccPac CRM and SuperOffice consultant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top