|
Posted by Whit on 10/30/27 11:57
Alright -
Although I don't entirely understand the onkeypress event handler,
here's what I think I have ... It appears that when you include a
return statement in the call, a true/false return value will
allow/prevent the value from appearing, respectively.
However, in my case, when a letter is pressed, it is not only that
letter that may need to be changed. Consider the folling example:
The user types:
Acute dog
And realizes they have mistyped. They then insert a space between 'A'
and 'cute'. This should change the 'c' to a 'C', even though it was not
the key that was pressed.
To this point I have accomplished this by formatting the whole line,
the setting the value of the field equal to it. This screws up the
cursor. In our previous example, after the space is typed, the cursor
should sit here:
A |Cute Dog
But the assignment causes it to forget the cursor position.
A Cute Dog|
Making insert-typing very difficult. How can I use onkeypress to solve
this? Can I change specific characters instead of just rewriting the
whole line?
Thanks very much,
-- whit
totalstranger wrote:
> On or about 9/5/2006 1:28 AM, it came to pass that Whit wrote:
> > I'm sorry, I wasn't explicit enough, I meant to say capitalize the
> > first letter of each word. Meaning I have to read the whole string, cap
> > the first letter of words and un-cap the rest, then re-assign it ... I
> > have already written the function for this. But re-assignment of the
> > whole string causes the field to forget where the cursor is ...
> >
> > Thanks,
> >
> > -- whit
> >
> > BootNic wrote:
> >>> Whit <whitnelson@gmail.com> wrote:
> >>> news: 1157428414.179080.327350@e3g2000cwe.googlegroups.com
> >>> I am trying to write a script which automatically capitalizes all the
> >>> words in a text field as the user types. (Called on onkeyup) I am
> >>> having 2 problems:
> >>>
> >>> 1. When I replace the users text in the field with the formatted text,
> >>> it forgets where the cursor was, and places it at the end.
> >>>
> >>> 2. Also at this point, if the user has exhausted the available area
> >>> and the text has started scrolling to the left, the replacing action
> >>> will cause it to forget it's position of the scroll, moving it so
> >>> that the begining of the text is flush with left side of the field.
> >>>
> >>> Can the cursor be managed? Can viewable area of a text field with text
> >>> overflow be managed?
> >>>
> >>> I have searched and searched for the solution to this problem.
> >>>
> >>> Could I perhaps build my own custom text field? Is there one out there
> >>> already built that I could use? Thanks in advance everybody!
> >> Basic resolution.
> >>
> >> <input type="text" style="text-transform:uppercase;"
> >> onchange="this.value=this.value.toUpperCase();"
> >> onkeyup="this.value=this.value.toUpperCase();">
> >>
> >> --
> >> BootNic Tuesday, September 05, 2006 1:15 AM
> >>
> >> Imagination was given to man to compensate him for what he isn't. A
> >> sense of humor was provided to console him for what he is.
> >> *Horace Walpole English novelist*
> >
>
> Suggest using onkeypress
> Get current character (varies by browser)
> Get current data in field and length of field
> If any alphabetic character beyond position 1 is proceeded by a space
> translate to upper case else translate to lower case.
>
> http://www.w3schools.com/jsref/jsref_onkeypress.asp
Navigation:
[Reply to this message]
|