1

I am using virtual keyboard plugin http://mottie.github.io/Keyboard/.
Here, in the mottie textarea I want to fire a keypress event, so that I can use the physical keyboard to enter the text in the seleted laguage.

I tried something like this

$('textarea[name=Notes]').keypress(function (e) {});

and like this also

$("div.ui-keyboard-preview-wrapper").find('textarea[name=Notes]').keypress(function (e) {});

I also tried like this

$(".ui-keyboard-preview").keypress(function (e) {});

But, its not triggering the event. Is there anyway to do this?

Bhola
  • 27
  • 1
  • 1
  • 5
  • Missing relevant context in question but have you tried delegating event? – A. Wolff Jul 23 '15 at 11:42
  • Can you explain what exactly you're trying to do with this code? The plugin does trigger a [`keyboardChange` event](https://github.com/Mottie/Keyboard/wiki/Methods#events) with every change made to the input/textarea. If you want to modify the text, [there are a few examples on the Home wiki page](https://github.com/Mottie/Keyboard/wiki#manipulating-text). – Mottie Jul 23 '15 at 15:19

1 Answers1

7

Try with input event like below code snippets. It will track the changes in textarea field. For the older version of IE propertychange event can be used to track the changes.

Sample code snippets:

$(document).on('input propertychange', "textarea[name='Notes']", function () {
    alert("Text Updated");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<textarea name="Notes" rows="4" cols="50">
Your text 
</textarea>

Note:

The input event will trigger whenever the content of the text area getting changed. But it will not hold the key press information of event.which. Instead you can use keypress or keydown or keyup events separately to track the key code.

But for Virtual keyboard you could try something like this Fiddle

Hope this helps you!

John R
  • 2,741
  • 2
  • 13
  • 32
  • Thanks John. Now the key event is triggering. But getting another problem. **e.which** and some other property is coming as undefined. Here In my program, I am also checking if user pressed special key like shift and ctrl. and these properties are also coming **undefined**. How to resolve it ? – Bhola Jul 23 '15 at 12:45
  • @Bhola Please check this. http://stackoverflow.com/questions/17384218/jquery-input-event Regret for the previous comment which I posted without testing. Hope you have understood the concept now. – John R Jul 23 '15 at 17:22
  • Thanks again John. I got the idea from this link and finally I come up with **$(document).on('keypress',"textarea[name='Notes']", function (e) { });**. And also first time I come to know about the **input** event. +1 from my side. Thank you – Bhola Jul 24 '15 at 04:30
  • @Bhola You are Welcome. – John R Jul 24 '15 at 06:03