Code:jQuery code
- function new_message(){
-
- var val = $(".chat_box").attr('id');
- var id_korisnika = val.substr(val.indexOf("_") + 1)
- //$('#korpa').html(id_korisnika);
-
- $(".chat_box").bind('keydown', function(e){
- alert(e.keyCode);
- e.preventDefault();
-
- });
- }
html code
<textarea class='chat_box' id='input_"+chatuser+"' placeholder='type message' onkeyup='new_message()' ></textarea>
Problem description (time line of problem):
1) The first time when i press any key on the keyboard, i do not have alert(e.keyCode)
2) The second time when i press any key on the keyboard, i have correct alert(e.keyCode)
3) The third time when I press the button on the keyboard, i have correct alert(e.keyCode), but 2 time alert`s
4) ..... i have correct alert(e.keyCode), but 3 time alert`s
5) ... and so on ....
Why this happens? Where is the problem ?
Alert instead, there should be standing at the mysql_query("insert into.... posts for inserting message in database, but, this code will be insert message "N" times in row... and that is not ok.
PS:
You can see the message box on attached picture (i have 2 same message in row)
(i try to upgrade chat box application, and i m try to be like chat on Facebook, everything that I had planned I've done, I've just not about sending this message -... i send messages, but the few times one and the same :S)
you can see example in atachment