javascript - I want to get an attribute from the textarea that uses the onkeypress event -
i have following code:
<div> <form name="comentario" id="<?php echo $id?>" action="funcion_enviar_comentario.php" method="post"> <input hidden="hidden" type="text" id="inputid" name="inputid" value="<?php echo $id?>"> <textarea class=estilotextarea1 id="comentario<?php echo $id?>" onkeypress="process1(event,this)" name="<?php echo $id?>" placeholder="introduce tu comentario aquí..."></textarea> <script> function process1(e) { //var ide= document.getelementbyid("comentario <?php echo $id?>").name; //var submit= document.getelementbyid("enviado<?php echo $id?>"). var code = (e.keycode ? e.keycode : e.which); if (code == 13) { $('form#comentario<?php echo $id?>').submit(); } } </script> </form> </div>
i want function process1 take attribute name textarea triggering event(this code inside php while query) store in variable can use variable submit form id matches variable. in advance.
if understand correctly, can use this:
<div> <form name="comentario" id="1" action="funcion_enviar_comentario.php" method="post"> <input hidden="hidden" type="text" id="inputid" name="inputid" value="1"> <textarea class=estilotextarea1 id="comentario1" onkeypress="process1(event,this.id)" name="1" placeholder="introduce tu comentario aquí..."></textarea> </form> </div> <div> <form name="comentario" id="2" action="funcion_enviar_comentario.php" method="post"> <input hidden="hidden" type="text" id="inputid" name="inputid" value="2"> <textarea class=estilotextarea1 id="comentario2" onkeypress="process1(event,this.id)" name="1" placeholder="introduce tu comentario aquí..."></textarea> </form> </div>
jquery:
function process1(e,id) { var code = (e.keycode ? e.keycode : e.which); if (code == 13) { alert('form #'+id); $('form #'+id).parent('form').submit(); } }
so, process1, shouldn't inside loop, can id, passing function parameter... demo: http://jsfiddle.net/msgosoal/1/
and, last line explanation - can't submit textarea, need target parent form...
Comments
Post a Comment