Array of textbox generated using following code:
if(mysqli_num_rows($result)>0)
{
$count=1;
while($row = mysqli_fetch_row($result))
{ ?>
<input type="number" name="marks[]" value="" id="marks' count '" min="0">
<?php
$count ;
}
}
**JQUERY CODE**
$(document).ready(function(){
$("#marks' count '").keypress(function(){
alert("Key is pressed");
});
});
My question is how to use keypress event on every textbox using jquery?
CodePudding user response:
Add a class to the inputs so you can select them all
Here you go:
if(mysqli_num_rows($result)>0)
{
$count=1;
while($row = mysqli_fetch_row($result))
{ ?>
<input type="number" name="marks[]" value="" id="marks' count '" min="0">
<?php
$count ;
}
}
**JQUERY CODE**
$(document).ready(function(){
$(".textbox").keypress(function(e){
alert("Key is pressed");
console.log(e.target); //this allows to see which input was pressed
});
});