WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Array values from javascript to php
Categories : PHP, Java Script, Arrays Click here to Update Your Picture
Fernando Dulanto
Date : Sep 22nd 2006
Grade : 2 of 5 (graded 2 times)
Viewed : 17460
File : 4500.TXT
Images : No Images for this code example.
Search : More code by Fernando Dulanto
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

How to carry an array value from javascript to php?

Explanation

The javascript array values can be passed to a php file using the following method :

Step 1: Let us consider we have a js array as
<script language=javascript>
scriptAr = new Array();
scriptAr[0] = "uno";
scriptAr[1] = "dos";
scriptAr[2] = "tres";
</script>


Step 2: Now we will create a hidden form field as follows
<form action="phpArrayTest.php" method=post name=test onSubmit=setValue()>
<input name=arv type=hidden>
<input type=submit>
</form>


Here what we have done is, when the submit is called we first do some work ("onSubmit=setValue()") by using the onSubmit method. The onSubmit method will invoke setValue() function defined by us.
After that the action will take place and stringTokens.php will be called.

Step 3: Here we define the setValue method. The method will convert the array periviously defined in to a string and then set it to the hidden field.
<script language=javascript>

function setValue()
{
var arv = scriptAr.toString();
// This line converts js array to String document.test.arv.value=arv;
// This sets the string to the hidden form field. }
</script>


Step 4:In the php file the string will be split back into array.
Let us consider we get a value from a post action one,two,three
i.e: $ss = $_POST['arv'];


Now using the php method explode() we will convert the string in to a array object :
explode(separator,string);
Example :  $tok = explode(',',$ss);


so we have got a string array. Now we print the array using print_r() method. This method prints the array in string format.

print_r($tok);

The result
Array ( [0] => one [1] => two [2] => three )



enhanced date picker with jcript checking for a dynamic date input
Categories : PHP, Java Script, Date Time, Calendar, Arrays
Dynamic Loading of XML array data into ComboBox and Display XML data using PHP + DOM + Javascript.
Categories : PHP, Java Script, DOM XML, XML, Arrays
Array values from php to javascript
Categories : PHP, Java Script, Arrays
PHP Array to Javascript Object
Categories : PHP, Arrays, Java Script
How to pass an array to a function, or how to define a function wich recieves an array.
Categories : Variables, PHP, Arrays
Sort the results from a SELECT query (any number of columns) into an array automatically.
Categories : PHP, PHP Classes, Arrays, Databases, MySQL
This simple function will take a few arguments and easily set a associative array for each column in a result from a MySQL query
Categories : Databases, PHP, MySQL, Arrays
Print out array key => value in colored HTML
Categories : PHP, Arrays, HTML and PHP
Looping through two arrays
Categories : PHP, Databases, Arrays
The meaning of your name
Categories : PHP, Arrays, Misc
Alert in JavaScript and Trace in Flash Action script are two commands that I find very much useful for tracking and debugging errors in my scripts. Unfortunately, there is no such option in PHP.
Categories : PHP, Java Script, Debugging
Can the word DO be used in arrays?
Categories : Arrays, PHP, Strings
columned txt file to array()?
Categories : Arrays, Strings, Regexps, PHP
Form Submission Using Array's
Categories : PHP, HTML and PHP, Beginner Guides, Arrays
Remote Scripting: send form POST data to a script and insert the results into a page without refreshing the page.
Categories : PHP, AJAX, HTML and PHP, Java Script