Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 13th, 2002, 12:00 AM
tim tim is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 62 tim User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 9 sec
Reputation Power: 17
Send a message via ICQ to tim
How do you communicate values to Javascript?

e.g.
I have the following variable defined in a PHP file(error.php) being required into another add form (say, add.php):

$error_message = "Please enter something";

In add.php, I 'require' / source in a javascript file. The javascript file contains a function to detect if something is empty upon me saving something. If it is, it prompts using alert(). What I have in this alert function is not text but I put in PHP variables like the following;
alert ('<?=$error_message?>');

However, it didn't work. Instead, it echoed the whole variable out literally. How do I communicate PHP variables contained in a required PHP file to the included javascript file's function?

I hope I made myself understood.

Please help because I need this in my multilingual project.
thanks
__________________
Beginner

Reply With Quote
  #2  
Old September 13th, 2002, 12:15 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
could you show us what printed out?

Reply With Quote
  #3  
Old September 13th, 2002, 10:58 PM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 588 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Your web server may have short tags disabled, use <?php instead of <?

Also, make sure the variables are defined as global in your PHP script if you're outputting the JavaScript in a function:

<?php

function myFunc()
{
global $var1;
global $var2;
...

Lastly, make sure you replace ' with \' when you output the variables from PHP.

Reply With Quote
  #4  
Old September 16th, 2002, 08:21 PM
tim tim is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 62 tim User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 9 sec
Reputation Power: 17
Send a message via ICQ to tim
For instance, if I say alert('<?=$char?>'); and $char = "A";
I am supposed to see the character 'A' in my pop up box but instead I see the whole literal <?=$char?> string

And no, it's nothing to do with the short tags.

Lastly, what do you mean by the global declarations?Didn't quite get you.

Reply With Quote
  #5  
Old August 13th, 2006, 03:14 AM
monkey56657 monkey56657 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 78 monkey56657 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 38 m 21 sec
Reputation Power: 13
I thought this was so easy.....And i first started learning php a month ago..

Anyway Tim. Ive added your icq. Its best to see more of the exact code cus im rubbish at explaining things and me trying to explain may not help you.

Here is what u have right?
Code:
.....ert('<?=$char?>'); a....


So what you do...way b4 u call the variable $char u must add the ' and ' at the start and end. so like this.

Code:
<?php
$char = "'".$char."'";
echo($char);
?>


So your final code wud be.

Code:
alert (<?php $char="'".$char."'"; echo($char); ?>);


Remember to keep the spaces. There important. Unlike u missed them out in ur example.


Im sure this is not the best way to do this but as im a beginner that is my way. Anyone has a shorter way then post plz.

To see in action visit http://www.3doms.com/private/dump/tim.php

Reply With Quote
  #6  
Old August 14th, 2006, 09:12 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
Wow, a four year old thread...
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter!
DevArticles Forum Moderator

"The net is a waste of time, and that's exactly what's right about it." -- William Gibson

Reply With Quote
  #7  
Old August 14th, 2006, 07:31 PM
monkey56657 monkey56657 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 78 monkey56657 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 38 m 21 sec
Reputation Power: 13
Quote:
Originally Posted by MadCowDzz
Wow, a four year old thread...


lol. i didnt realise. found this post while searching google for something so signed up n answered

I shudnt expect an answer then lol.

Reply With Quote
  #8  
Old August 15th, 2006, 09:25 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
I didn't mean to discourage or degrade the answer.
It might help others who stumble across the thread on Google.

Reply With Quote
  #9  
Old August 15th, 2006, 09:50 AM
monkey56657 monkey56657 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 78 monkey56657 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 38 m 21 sec
Reputation Power: 13
Safe!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > How do you communicate values to Javascript?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap