Reputation: 89
Let say I have a $_SESSION['password'] and a javascript function.
Here's the javascript function:
<script>
function check() {
var password = '<?php echo $_SESSION; ?>';
alert(password);
if (document.FormName.password.value != password)
alert("password does not match");
}
</script>
<html>
//form here
</html>
How come when the alert pop-ups, it will only display nothing? what happened? Is my passing of variable wrong at all?
Upvotes: 0
Views: 182
Reputation: 3494
<script>
function check() {
var password = "<?=$_SESSION['password']?>";//you forgot ['password'] here
alert(password);
if(document.FormName.password.value != password)
alert("password does not match");
}
</script>
<html>
//form here
</html>
Upvotes: 0
Reputation: 15603
$_SESSION
is an array and this will return blank if you echo it.
You should use the
<?php echo $_SESSION['password']; ?>
It will echo the password that store in Session.
Upvotes: 1