<?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?
should be
It works when
genderdbis"Female", because then the (broken) second comparison doesn’t come into the equation.In addition, using
varinside the conditional blocks is suspect. Javascript actually doesn’t have block scope so it works, but it’s something to consider.