views:

450

answers:

2

Hi, I want get the value of the text including the character on the keydown event.

$(".searchfield").keydown(function(e) {

  if (e.which >= 32 || e.which < 127) {
   var c = String.fromCharCode(e.which);
       callSearch($(this).val() + c));
  }
});

It works good for characters, numbers and all the essential characters. 32-127 ASCII range.

I am not sure if this will work if the textbox has a multilingual input. Non english characters.

Can someone share their experience please?

Thanks,

A: 

Hmm maybe you should put what character you dont want to triger this function, like 0-31 ascii characters and accept all other?

GaVrA
I guess it has to go this way...
LibraRocks
A: 

this will cover Spanish:

 $(".searchfield").bind("keypress", function(event) {
  var save = false;
  if (window.event) { event = window.event; }

  if (event.keyCode >=  32 && event.keyCode <= 126)      { save = true; }
  else if (event.keyCode == 259)              { save = true; } // Y
  else if (event.keyCode >= 192 && event.keyCode <= 197) { save = true; } // A
  else if (event.keyCode >= 200 && event.keyCode <= 203) { save = true; } // E
  else if (event.keyCode >= 204 && event.keyCode <= 207) { save = true; } // I
  else if (event.keyCode == 209)              { save = true; } // Ñ
  else if (event.keyCode >= 210 && event.keyCode <= 214) { save = true; } // O
  else if (event.keyCode >= 217 && event.keyCode <= 220) { save = true; } // U
  else if (event.keyCode == 221)              { save = true; } // Y
  else if (event.keyCode >= 224 && event.keyCode <= 229) { save = true; } // a
  else if (event.keyCode >= 232 && event.keyCode <= 235) { save = true; } // e
  else if (event.keyCode >= 236 && event.keyCode <= 239) { save = true; } // i
  else if (event.keyCode == 241)               { save = true; } // ñ
  else if (event.keyCode >= 242 && event.keyCode <= 246) { save = true; } // o
  else if (event.keyCode >= 249 && event.keyCode <= 252) { save = true; } // u
  else if (event.keyCode == 253)              { save = true; } // y
  else if (event.keyCode == 255)              { save = true; } // y

  if (save){
    var c = String.fromCharCode(event.keyCode);
   callSearch($(this).val() + c));
  }
 });
andres descalzo