RE: Javascript question... any guru's out there?

by "Brett" <brett(at)opensearch.com>

 Date:  Sat, 10 Aug 2002 00:13:53 +0800
 To:  "'HWG-technique Mailing List \(E-mail\)'" <hwg-techniques(at)hwg.org>
 In-Reply-To:  wtc
  todo: View Thread, Original
>From what I can imagine this can't be done safely :)

By that I mean.... every number is a different word. Think about it 1 is
one, 5 is five, 22 is twenty two, 101 is one hundred and one. You would
have to have an array of all those word values stored which is
ridiculous (because you are probably looking at least 99 entries in the
array). But anyway it can still be done with something like:

wordArray =3D newArray();
wordArray[0] =3D "One";
wordArray[1] =3D "Two";
wordArray[2] =3D "Three";
...

for ( i =3D 0; I < wordArray.length; i++ )
{
	strPass.split(i).join(wordArray[i]);
}

You may be able to find a slightly more efficient method but I still
don't think it will run fast enough to by put on every keyUp.

Later,
Brett
=A0
"Ooooh..... they have the Internet on computers now"
- H. Simpson

-----Original Message-----
From: owner-hwg-techniques(at)hwg.org [mailto:owner-hwg-techniques(at)hwg.org]
On Behalf Of Davies, Elizabeth H.
Sent: Friday, 9 August 2002 10:12 PM
To: HWG-technique Mailing List (E-mail)
Subject: Javascript question... any guru's out there?

Is it possible to substitute values in a textbox and retain the
previously typed input? The requirement is to have a textarea that
allows only alphabetic characters, brackets and the single quote -- no
punctuation. In addition, any number is "translated" to it's word
equivalent. So if I type:

"They're all inside 9, maybe 10 cars." ... I would get:

"They're all inside nine maybe onezero cars"

I've come up with the following which eliminates the illegal characters
yet allows alphabetic, numeric, brackets and the single quote.... This
part works, but I've been unable to get the second part done....I
thought I could then screen for the numbers and then perform a one to
one value substitution. I can't figure out how to grab the numbers,
substitute the word equivalent and add them back to the string. My
feeble attempt simply replace the entire string with the one word and
then stops you from entering anything else. The programmer wants the
action to occur on KeyPress, which I was completely stumped at... ANY
IDEAS? Please? I've searched and searched and have come up empty.... (in
case your wondering, it's for transcriptions... it would be nicer on the
workers to automatically put in the numbers rather than force them to
type it as words)

<head>

<script type=3D"text/javascript" language=3D"JavaScript1.2">

var charField =3D /[\w\'\s\[\]]/;

function docheck(val) {
var strPass =3D val.value;
var strLength =3D strPass.length;
var lchar =3D val.value.charAt((strLength) - 1);

if(lchar.search(charField) =3D=3D -1) {
	var temp =3D val.value.substring(0, (strLength) - 1);
	val.value =3D temp;
   }=20
}

</script>
</head>

<body>
<form name=3D"transcribe">
<textarea name=3D"text_area"
onKeyUp=3D"javascript:docheck(document.transcribe.text_area);">
</textarea>
</form>

</body>
</html>

Elizabeth Davies
Web Designer
West Corporation
(402)573-3386 or X206-7562

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA