Re: question about javascript and textboxes for Pros
by David Mintz <mambomintz(at)yahoo.com>
|
Date: |
Thu, 11 Jan 2001 09:05:51 -0800 (PST) |
To: |
hwg-languages(at)hwg.org |
|
todo: View
Thread,
Original
|
|
Now *that's* interesting! I take it you would write an
event handler for the onkeypress event of this
textbox?
You lost me in the part about appending to an
accumulating string. Why not just use the the string
in
textbox.value?
Just for kicks I wrote this little script that does
something when the user takes more than half a second
between keystrokes following the first keystroke. Is
this the idea, sort of?
<script language="javascript1.2">
var then, now;
function startTimer(string) {
var diff;
if (now) { then = now; }
now = new Date();
if (then) { diff = (parseInt(now - then));}
if (diff > 500) {
alert("more than .5 sec, so do something with " +
string);
then = 0; now = 0;
}
}
</script>
--- Cyanide _7 <leo7278(at)hotmail.com> wrote:
> if you've already got that much, i'll just throw the
> logistics at ya. for
> this i recommend a timer. much like how a double
> click is registered, it
> merely checks when the action was last made. for
> each captured "keypress"
> event, grab the time and compare it to the time of
> the last key press. save
> the current time for the next comparison. then, if
> the difference in time is
> withing the right interval (say 500 ms) then you
> append the current
> keystroke to an accumulating string, use that to
> match the nearest option.
> otherwise, clear the appended string and start a new
> one. its a simple
> algorithm to toss into your existing code im sure.
> good luck - Cyanide_7
>
> >--- Siim Einfeldt aka Itpunk <siim_e(at)pshg.edu.ee>
> >wrote:
> > >
> > >
> > > one problem solved:-) ok, I can now type f,
> but
> > > what if I wanted to
> > > write fe (f and e) or even feb (f and e and b)?
> > >
> >
> >Ah, now that's trickier! Go ask Cyanide (-:
> >
> >But if you ask me, well, AFAIK, if would wanted to
> >approximate that kind of behavior I think you'd
> have
> >to have a separate textbox, and prompt the user to
> >type the first 2 (or 3, or 4) characters of the
> >item/number and click something, which would
> trigger a
> >function that would loop through your OPTIONS array
> >comparing strings, and set the matching element of
> the
> >options array's SELECTED attrib to true when it
> hits a
> >match, and then exit the loop. And give them a
> >window.alert message saying "sorry, we ain't got
> that"
> >if you get to the end without finding a match.
> >
__________________________________________________
Do You Yahoo!?
Yahoo! Photos - Share your holiday photos online!
http://photos.yahoo.com/
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA