views:

1806

answers:

3

Hi, I'm using jqGrid plugin and I want to add onKeyPress event to each field of edit form.

This code works for IE8, but fails in FF and IE7

 {name: 'name', index: 'name', width: 200, editable: true, 
     sortable: false, search: true, editoptions: { readonly: false, size: 32, 
     'onKeyPress': 'if($("#cbLanguage").attr("checked"))togeo();' }, 
     editrules: { required: true }}

How to modify this to make it work in IE7 and FF? Thanks.

+1  A: 

Try using onKeyup instead.

karim79
didn't help.....
Sorantis
+1  A: 

Kudos to karim79 for spotting the event issue.

In addition You will be better of using a function rather than an implied string as a function. Easy to read/maintain.

name: 'name', index: 'name', width: 200, editable: true, 
     sortable: false, search: true, editoptions: { readonly: false, size: 32, 
     'onKeyUp': keyUpFn }, 
     editrules: { required: true }}



function keyUpFn (){

 $("#cbLanguage").is(':checked') ){
   togeo();
 }

}
redsquare
no, unfortunately it didn't help
Sorantis
A: 

Found the solution! In order to assign event to field I need to add following to editoptions:

dataEvents:[{type:'keypress', fn: function(e) {
if($("#cbLanguage").attr("checked"))togeo(); }}]
Sorantis