Natsukawa Masuzu Natsukawa Masuzu - 2 months ago 23
jQuery Question

javascript if php variable is bigger or smaller

I have a PHP form that get data from database and echo it. I want to know how can I make something to compare the results and echo something.

$variable = 15<br>

I want something like:

if $variable < 15 echo "bad"
if $variable > 15 echo "good"
if $variable = 15 echo "not bad"


First assign the value of your PHP variable into a javascript var

    var variable_name = "<?php echo $variable;?>";

Then do the checking

var comments       = "Not Bad";
    if(variable_name < 15){
        comments      = "Bad";
    else if(variable_name > 15){
       comments       = "Good";