Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Accepting only Upper Case characters in input field

583687Dec 15 2009 — edited Dec 16 2009
Hello,

I want to accept only upper case characters in input field component. When user types any character, it should automatically convert it to upper case.
After doing some research(Checking forum, Google), i found following ways,

Using converters, but this will work when user do a focus lost after entering the value.
Adding a style class, but the actual value submitted can be in any case.

I want something like while typing only, character should get converted to upper case. There is one more way, but this way works only in IE, it doesnt work in Firefox.
1. Add one ClientListener of type keyPress on the component (tfdComponent),

ClientListenerSet l_clientListeners = tfdComponent.getClientListeners();
l_clientListeners.addListener("keyPress", "convertToUpperCase");
tfdComponent.setClientListeners( l_clientListeners);

2. Now in the java script function, just conver the current input key code to upper case and set it back. This can be done as,

function convertToUpperCase( _event ) {
var currText = null;
currText = String.fromCharCode(window.event.keyCode);
window.event.keyCode = currText.toUpperCase().charCodeAt(0);
}

But above approach only works in IE as window.event object is provided by IE.
I need a good way to achieve this functionality in any browser.

- Sujay
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 13 2010
Added on Dec 15 2009
4 comments
1,854 views