My problem is that it only works if I click on the button and if I place the keydown then I have to tab on the button and hit enter. I want it to work by clicking the send button and hitting enter in the field like chats. any idea how to do it.
<form id="mensajeform">
<input type="text" id="nick" value="<?php echo $_SESSION["nombres"];?>" hidden>
<input id="mensaje" placeholder="Escribir un mensaje aqui" id="first_name" type="text" class="validate col s11">
<div id="enviar" style="background-color: transparent;border: transparent;"><img src="views/imagen/enviar.png"></div>
</form>
$("#enviar").click(function(){
nick = $("#nick").val();
mensaje = $("#mensaje").val();
console.log(nick,mensaje);
});
Create a function with the send functionality and call it from both the
click
button event and thekeydown
text box event if the key pressed is Enter: