PHP vars in JavaScript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Dingbats
Forum Commoner
Posts: 25
Joined: Fri Dec 05, 2003 10:53 am

PHP vars in JavaScript

Post 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?
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post 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>
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

I suggest you to read the following posts:Regards,
Sco.
Dingbats
Forum Commoner
Posts: 25
Joined: Fri Dec 05, 2003 10:53 am

Post 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?
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

Yeh, Dingbat..it does.... :)
Dingbats
Forum Commoner
Posts: 25
Joined: Fri Dec 05, 2003 10:53 am

Post by Dingbats »

Yay!
Post Reply