I am trying to save the PHP array and $_POST value in to javascript variable but it does not work.
This is how i am doing it.
<html>
<script>
var username = <?php echo $_POST['username']; ?>
var password = <?php echo $_POST['password']; ?>
//abc(username, password);
document.write(username+' '+password);// does not work
</script>
<body>
<form method="post">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" value="login" />
</form>
</body>
</html>
How can i achieve this?
If i pass a hard coded variable to JavaScript function, that works only. Let me show you how.
<script>
function func(v1, v2){
document.write(v1+' '+v2);// does not work
}
</script>
<?php
$a = 25;
$b = 30;
echo '<script>func('.$a.','.$b.');</script>'
?>