How to set dynamic values with onKeyUp javascript?

76 Views Asked by At

How can I set dynamic values for function onKeyUp? Right now I'm hardcoding the number but I need to retrieve it from a php variable.

php value

$num = $queryResults['col_number'];

html

<input onKeyUp="if(this.value>'$num'){this.value='$num';}
else if(this.value<0){this.value='0';}" />
1

There are 1 best solutions below

0
On BEST ANSWER

You need to output the value using <?php echo $num ?> or shorter <?= $num ?>

<input onKeyUp="if(this.value>'<?= $num ?>'){this.value='<?= $num ?>';} else if(this.value<0){this.value='0';}" />