EasyUI Forum
March 29, 2024, 12:36:47 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: enter key on textbox  (Read 15895 times)
crosemffet
Jr. Member
**
Posts: 68



View Profile WWW Email
« on: January 21, 2016, 01:40:25 AM »

hello everybody and thanks again for your support.
I have one textbox in my chat window. the idea is send the message on enter key (13).
that's my textbox:

<input id="write_input" class="easyui-textbox" data-options="prompt:'write here...',iconWidth:22,icons:[{iconCls:'icon-add',handler:function(e){sendChatMessage($(e.data.target).textbox('getValue'),'1');}}]" style="width:238px;height:24px;">

var t = $('#write_input');
t.textbox('textbox').bind('keydown', function(e){
   if (e.keyCode == 13){   // when press ENTER key, accept the inputed value.
      t.textbox('setValue', $(this).val());
   }
});

the textbox works like a charm, except that I need to send the message on enter key, not only on icon-add click, and when I add the line:
t.textbox('textbox').bind ..... trows error (unable to get the value of the property textbox. object is null or undefined.
any idea...?
thanks in advance,
« Last Edit: January 21, 2016, 02:22:39 AM by crosemffet » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: January 21, 2016, 07:24:09 PM »

You should put your code inside $(document).ready() block.
Code:
$(document).ready(function(){
var t = $('#write_input');
t.textbox('textbox').bind('keydown', function(e){
   if (e.keyCode == 13){   // when press ENTER key, accept the inputed value.
      t.textbox('setValue', $(this).val());
   }
});
})
Logged
bvn
Newbie
*
Posts: 13


View Profile
« Reply #2 on: July 20, 2017, 08:16:23 AM »

What about another controls?
For example 'passwordbox' and 'switchbutton'.
I tryied to do $('#password').passwordbox('passwordbox').bind('keyup', ... ); but it does not effect.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: July 21, 2017, 03:29:37 PM »

Please call the 'textbox' method to get the inputing box and bind events on it.
Code:
$('#password').passwordbox('textbox').bind('keyup', ... );
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!