Page 1 of 1
PHP vars in JavaScript
Posted: Mon Jan 12, 2004 8:11 am
by Dingbats
I just wonder, is it possible to use PHP variables in JavaScript in any way? I'm asking because I'm going to create a user registration form for a community in the future, and I want a JavaScript alert box to pop up if the username you wrote already exists. That way the registration would be faster. Anyway, is it possible?
Posted: Mon Jan 12, 2004 8:48 am
by igoy
you have PHP var like ... say a session var called
uname
Code: Select all
<script language="javascript" type="text/javascript">
<!--
var popname = <?php echo $_SESSION['uname']; ?>
alert("hello "+popname);
//-->
</script>
Posted: Mon Jan 12, 2004 4:56 pm
by scorphus
I suggest you to read the following posts:
Regards,
Sco.
Posted: Tue Jan 13, 2004 9:14 am
by Dingbats
<script language="javascript" type="text/javascript">
<!--
var popname = <?php echo $_SESSION['uname']; ?>
alert("hello "+popname);
//-->
</script>
Does this work with other vars like $whatever?
Posted: Wed Jan 14, 2004 2:47 am
by igoy
Yeh, Dingbat..it does....

Posted: Wed Jan 14, 2004 12:11 pm
by Dingbats
Yay!