<?php $genderdb = "Male"?>
<script type="text/javascript">
var genderdb = "<?php echo $genderdb; ?>";
if ((genderdb == "Female") || ($genderdb == "Shemale")) {
var himher = "her";
} else {
var himher = "him";
}
alert (himher);
</script>
If I change php $genderdb = "Female", then it can alert the value successful. But if $genderdb = "Male", the page won't have alert. Why? Where is the error?
$supposed to be there in the JavaScript if?genderdb == "Female", theifcondition istrueand so the second half doesn't have to be evaluated at all. Ifgenderdb != "Female", the second half of that condition has to be evaluated, resulting in an undefined symbol error. You should be seeing it in the JavaScript console of whatever browser you're using.<?=$genderdb?>instead of<?php echo $genderdb; ?>