Keyboard Events

1,129 views
Skip to first unread message

amandeep

unread,
Mar 2, 2010, 8:51:50 AM3/2/10
to phonegap
Hi,

Can we access keyboard events using javscript in Phonegap. I want to
fire a function on clicking go button of the iphone inbuilt Keyboard

Jesse MacFadyen

unread,
Mar 2, 2010, 7:56:58 PM3/2/10
to amandeep, phonegap
If you want to catch the 'GO' action on a keyboard event, you need to wrap the input in a form tag and  add your functionality to onsubmit

ex.

In html :

<form onsubmit="onProfileSubmit(event);">
<... inputs ...>
</form>

and in js

function onProfileSubmit(e)
{
    // do some validation, or whatever ...
    // if you don't preventDefault, your page may reload, depending on              the action of your form
e.preventDefault();
}

If you want to handle individual key events, example to limit the length of text in an input:

in html:

<textarea id="taStory" onkeypress="onStoryKey(event);" ></textarea>

and in js:

function onStoryKey(e)
{
// allow the delete key, otherwise limit length
        // 8 is the delete key ( we allow it ) ??!
if(e.target.value.length > 140 && e.keyCode != 8) 
{
e.preventDefault();
}
}

Okay, that's my whole bag o tricks, pass it on.
onkeypress, onkeyrelease, all DOM events exist and are no different than writing javascript for the web.


--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com



--
--
Jesse MacFadyen
{
 blog:'blogs.nitobi.com/jesse',
 email:'jesse.m...@nitobi.com',
 company:
 {
   name:'Nitobi Software',
   site:'www.nitobi.com',
   phone:
   {
     office:'+1 (604) 685-9287',
     tollFree:'1-866-632-2777'
    }
 }
}

amandeep

unread,
Mar 3, 2010, 2:58:42 AM3/3/10
to phonegap
Hi,

I want to access keyboard events i tried the above mentioned solution
but it is not working, but i am using jquery in my project is there
any problem due to that plz reply if any solution

abritez

unread,
Apr 1, 2010, 5:46:05 PM4/1/10
to phonegap
You rock, missed that e.preventDefault on search input, and it was
driving me bananas!

> > phonegap+u...@googlegroups.com<phonegap%2Bunsu...@googlegroups.com>


> > For more options, visit this group at
> >http://groups.google.com/group/phonegap?hl=en?hl=en
>
> > For more info on PhoneGap or to download the code go towww.phonegap.com
>
> --
> --
> Jesse MacFadyen
> {
>  blog:'blogs.nitobi.com/jesse',

>  email:'jesse.macfad...@nitobi.com <email%3A%27jesse.macfad...@nitobi.com>',

Reply all
Reply to author
Forward
0 new messages