Welcome!

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

Reply
Retired
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:

 

 

<html>
<head>
<title> Browser: Focus </title>
<script type="text/javascript">
   function applyFocus(id)
   {
	document.getElementById(id).focus();
   }
   function endFocus()
   {
	applyFocus("btnApply");
   }
   function startFocus()
   {
   	applyFocus("txtText");
   	setTimeout(endFocus, 2000);
   }
</script>
</head>
<body onload="setTimeout(startFocus, 2000)">
<h1>Browser: Apply Focus</h1>
<p>
   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.
</p>

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

 

Let me know if you found this helpful.

 

Cheers,

Adam

 

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....