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

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 29th, 2000, 08:32 PM
mfkoo mfkoo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 65 mfkoo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
I am developing a page using PHP, but now i need javascript to do some extras function like onclick. So, i need to know a varaible set used in PHP can pass to JS or not.....

Reply With Quote
  #2  
Old May 29th, 2000, 08:58 PM
jonherron jonherron is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 24 jonherron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Why not use your PHP to write your javascript, for instance:

<?

$someVar = "this";
$someVar2 = "that";

$strJS = "<script language="JavaScript">nn";
$strJS .= "var myArray = new Array();n";
$strJS .= "myArray[0] = $someVar;n";
$strJS .= "myArray[1] = $someVar2;n";
$strJS .= "alert("First val from PHP: " + myArrayp[0]);n";
$strJS .= "</script>nn";

?>

This is pretty simple, but note i didnt test this code so i probably forgot a or a semi somewhere so cut me some slack on it.

Reply With Quote
  #3  
Old May 29th, 2000, 08:59 PM
jonherron jonherron is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 24 jonherron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
P.s.

I guess it would help to add this line:

echo($strJS);

Hope i was at least a little help.

Reply With Quote
  #4  
Old May 29th, 2000, 09:27 PM
mfkoo mfkoo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 65 mfkoo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
Thanks for reply.

How about i want a value passing from javascript to php...like

<script=javascript>
var str ="This is a test";
</script>

and i print it using php like,

echo $str;

will it done????

Reply With Quote
  #5  
Old May 30th, 2000, 02:58 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan

<<
<script=javascript>
var str ="This is a test";
</script>

and i print it using php like,

echo $str;
>>


if you are writing the <<var str="This is a test">> in side java script then it will consider this as a java script variable.
so you can't call like $str.

that means this java script values will be going to the client browser.

Right now 'str' javascript variable is not carrying any value.This variable will be activated only in client side.

So you can't get that java script variable value in server side.

if you want to get the same value in php also,then you will have to assain this value directly to php variable.




------------------
SR -
shiju.dreamcenter.net

"The fear of the LORD is the beginning of knowledge..."

Reply With Quote
  #6  
Old May 30th, 2000, 03:56 AM
okhvatstas okhvatstas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 33 okhvatstas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
All previous advice was correct - you can't combine a server-side language with a client-side one. I have only one thing to advise to you - pass your variable to a href which leads to your php file, in the form (for example) myfile.php3?lang=eng + 'MyVariable'. In an anchor, you have to combine it with <a href="javascript:....."
This is an example of how I combine Javascript and PHP to make a page modification script in two languages displayed in two frames:

<script>
function load(url) {
top.frames[1].location.href=url + '&lang=ru';
top.frames[2].location.href=url + '&lang=eng';
}
</script>

<select name="select" ONCHANGE="load(this.options[selectedIndex].value)">
<option value="text1.php3?cat=aboutme">Welcome page</option>

This script is in the first frame and controls the two frames below - they display the same page in two languages. You don't have to write a function for your case. I am not very experienced in Javascript, but you may even ask on the javascript forum on devshed how to do this.
Good luck

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP + JS

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 - 2013, Jelsoft Enterprises Ltd.

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