Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

How to open the virtual keyboard using JavaScript

Heya devs,


I wanted to share the following tip on how to programatically open the virtual keyboard from your WebWorks application.  Depending on the UX you are trying to achieve from within your application, it may be nice to promt your users to complete an input field upon the inial load of your page (e.g. a login screen).


This behavior is achieved by using the focus() JavaScript method, like this:



<title> Browser: Focus </title>
<script type="text/javascript">
   function applyFocus(id)
   function endFocus()
   function startFocus()
   	setTimeout(endFocus, 2000);
<body onload="setTimeout(startFocus, 2000)">
<h1>Browser: Apply Focus</h1>
   After 2 seconds, focus will be applied to the 'Hello World' text field.  
   2 seconds after that, focus will be removed from the text field (and applied to the button).  The net result will be that the user sees the virtual keyboard appear and then disappear.

	<button id="btnApply" onclick="applyFocus('txtText')">Apply Focus --> </button>
	<input type="text" id="txtText" value="Hello World" />
	<button onclick="applyFocus('btnApply')"> <-- Remove Focus </button>


Let me know if you found this helpful.





Follow me on Twitter: @n_adam_stanley
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Regular Contributor
Posts: 82
Registered: ‎11-12-2010
My Device: Android Droid Incredible
My Carrier: Verizion

Re: How to open the virtual keyboard using JavaScript

this is helpful thank you. Also wondering how do you tell the keyboard what type it should display on focusing onto the textfield? I.E. email, pin, url, qwerty....