Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
| Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 8th, 2004, 03:33 AM
Registered User
 
Join Date: Nov 2004
Location: Bangalore, Karnataka, India.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to youngj
Default Passing data from PHP to Javascript

Hi,
I want to pass an array from PHP to Javascript, without using hidden variables.My array size is unknown

Young j
  #2 (permalink)  
Old November 15th, 2004, 08:20 AM
Authorized User
 
Join Date: Oct 2004
Location: Edinburgh, Scotland, United Kingdom.
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default

Hmmm, im no expert, but you could use ur PHP code to generate the variable, for instance

echo "<script language=javascript> .... blah blah jscript stuff....";
$lego = array(1,2,3);


// Not 100% sure how to define an array in jscript, but somethign along the lines of this

$jscript_array = "array myArray = new Array(";
for($i;$i<count($lego);$i++) {
$jscript_array .= $lego[$i] . ", ";
}

$jscript_array .= ")\;";

Might sound a bit confusing, but hopefully you get me..

Many shoes,

James/SiliconFuRy
  #3 (permalink)  
Old November 15th, 2004, 10:58 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Try this:

[code]echo "<script type='text/javascript>";
echo "var array_from_php = new Array();";
foreach($your_array as $v)
{
    echo "array_from_php = '".$v."';";
}
echo "</script>";

Try that and tell me if array_from_php has the value you want.

-Snib
Where will you be in 100 years?
Try new FreshView 0.2!
  #4 (permalink)  
Old January 4th, 2005, 04:44 AM
Registered User
 
Join Date: Nov 2004
Location: Bangalore, Karnataka, India.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to youngj
Default

Thanks a lot snib, it does work, meanwhile I also found the Quickforms from PEAR, serves my purpose

Young j
  #5 (permalink)  
Old February 22nd, 2006, 11:55 PM
ama ama is offline
Registered User
 
Join Date: Feb 2006
Location: colombo, , Sri Lanka.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Snib can send rest of the code



Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing data from PHP to Javascript oldBroh Javascript How-To 12 June 12th, 2008 11:12 PM
Passing javascript variable to html or php ashraf_gawdat Javascript How-To 3 July 12th, 2006 02:48 PM
Passing PHP variables to javascript wfrisch Pro PHP 10 April 5th, 2005 05:13 AM
passing php variable to javascript and vice versa onmcv Beginning PHP 0 March 24th, 2005 01:00 PM
passing javascript to php by Snib ismnanie Pro PHP 5 February 4th, 2005 07:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.