I am trying to call a function validatQty on onkeypress and onkeydown event of a text. It was working fine when I was just passing event (single parameter) to this function. But when I tried to add a second parameter which I am getting through PHP, the function is not getting called anymore. Where is the error in my following code.
In my PHP File
<input type="text" id="txtAnyName"
onkeypress='return validateQty(event, <?php echo $data['anyName']; ?>)'
onkeydown='return validateQty(event, <?php echo $data['anyName']; ?>)'>
Javascript file
function validateQty(event, anyName)
{
alert(anyName);
var key = window.event ? event.keyCode : event.which;
if ( key < 48 || key > 57 )
{
return false;
}
}
you missing double quotes in your function...
<input type="text" id="txtAnyName"
onkeypress='return validateQty(event, "<?php echo $data['anyName']; ?>")'
onkeydown='return validateQty(event, "<?php echo $data['anyName']; ?>")'>
here is working example of jsbin