pass var from php to javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bmcg61
Forum Newbie
Posts: 1
Joined: Sun Nov 01, 2009 7:19 am

pass var from php to javascript

Post by bmcg61 »

When user sends email from form page, php files sends user back to form if email fails, redirects to home if email succedes. I want to pass a variable when I redirect to tell if user needs to be alerted of the status of email. but the alert always says "undefined". noob, obviously.

php-
/* set var to 3. var is set to 0 for failed email and 1 for successful email b4 redirect.
$alert_user = "3";
.............................
$bad_url = AddURLParams($bad_url,$a_params,false);
$alert_user = "0";
Redirect($bad_url);
................................
$alert_user = "1";
Redirect($SPECIAL_VALUES["good_url"]);

js on home page-
<script type="text/javascript" src="AA2.js">
//var alerted =(<?php $alert_user ?>);
alert ("<?php $alert_user ?>");
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: pass var from php to javascript

Post by jackpf »

Javascript needs quotes around strings.
Post Reply