Jquery get id of textbox that has had enter pressed? -
i have multiple text boxes ids manual_input_1, manual_input_2, manual_input_3. want stop form submiting when enter pressed in textboxes.
the code below know whole id of textbox pressing enter can box's value. e.g. manual_input_2 pressed enter, value = 1234.
$('[id^="manual_input_"]').keydown(function(e) { if(e.which == 13) { e.preventdefault(); var id = ?; <--- id of textbox pressed enter var value = ?; <--- value of textbox pressed enter alert('enter pressed '+id+'\n'+ 'value = '+value; ) return false; } }); can done? examples helpful.
thanks
you can "id" with
var id = this.id; and value with
var value = this.value; the jquery event dispatch layer ensures this refers affected element when handler called.
Comments
Post a Comment