I want to use a php boolean variable inside a jquery if-statement. This is my code:
if(<?php echo $show_login_error ?>)
$(".login_error").show();
.login_error is a class for a span element. If the $show_login_error variable is true, then I want to show the span, if not then hide it. By default the span is hidden and $show_login_error is false. Unforunately, the span shows regardless of the variable value so I’m guessing my code is wrong. What should I change to make it right? Thanks
First, make sure
.login_erroris hidden by default (display:none).Then, try
just to make sure it prints 0 or 1 (because
echo falsedoesn’t print a single character)EDIT
Other solutions provided below will work too! 😉