473,396 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

js array -> php array

Hi,

I have an array in javascript of which the contents are manipulated by
the user. When he is done, he calls a function to reload the page. Then
conclusion depending on the input should be printed.
The problem is, how can I use the javascript array in this php file?
Is it neccesary to use numerous hidden form fields for this purpose?

regards,

Roderik
Jul 17 '05 #1
2 2137
Roderik <ma**@roderik.net> wrote:
The problem is, how can I use the javascript array in this php file?
Is it neccesary to use numerous hidden form fields for this purpose?


cause javascript is executed on client browser and php script on server
: yes.

you have 3 methods for passing javascript values to your php script :

1- hidden (or not) fields of a form ;
2- link with url like www.script.php?var1=val1&var2=val2...
/!\ : you must serialize ?var1=val1&var2=val2... :
3- cookie string

--
@@@@@
E -00 comme on est very beaux dis !
' `) /
|\_ =="
Jul 17 '05 #2
denisb wrote:
Roderik <ma**@roderik.net> wrote:
The problem is, how can I use the javascript array in this php file?
Is it neccesary to use numerous hidden form fields for this purpose?

cause javascript is executed on client browser and php script on server
: yes.

you have 3 methods for passing javascript values to your php script :

1- hidden (or not) fields of a form ;
2- link with url like www.script.php?var1=val1&var2=val2...
/!\ : you must serialize ?var1=val1&var2=val2... :
3- cookie string


further to roderick's reply:

an array passed back to the server in a hidden form field will arrive in
your PHP script as a comma-delimited list, either in a POST variable, or
a GET variable.

this example uses the POST method --

<form name="testForm" action="test.php" method="post">
<input type="text" name="testText">
<input type="hidden" name="testHidden">
<input type="submit">
</form>

<script language="javascript">
testArray = new Array (1,2,3);
document.testForm.testHidden.value = testArray;
</script>

<?php

if (isset($_POST['testHidden'])) {
$tok = strtok($_POST['testHidden'], ",");
while ($tok) {
echo "element = $tok<br>";
$tok = strtok (",");
}
}

?>
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bob Bedford | last post by:
I've this structure in a XML file: Type Model Detail Datas Datas Datas Datas /Detail Detail
12
by: JKop | last post by:
template<class T> inline T& NthArrayMember( T & (array),size_t i) { return array; } template<class T> inline const T& NthArrayMember( const T & (array),size_t i) { return array;
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
0
by: Marc van Boven | last post by:
I'm stuck with the following problem: My nusoap-client calls a server-function giveCombination(). The function giveCombination should return something like array( => array( 'a_id' => 6,...
7
by: Eric Boutin | last post by:
Hi ! I would like to generate an array of type char; I just dont really figure out how I could do it with malloc or calloc.. I mean.. I know how to allocate a simple array with both of them;...
10
by: Steve | last post by:
this code: private Array m_arrays = new Array; results in an array of 3 null Array objects. What am I missing?
6
by: davidb | last post by:
Hi, does someone know how to get the length of a 2 dimensional string array: here what i need: ---------------------------------------------------------------- char **getList(void){ char...
2
by: Kenneth Brody | last post by:
Given the following current definition: int array; Is the following equivalent? (By "equivalent", I mean that any reference to "array" retains the same meaning, and that the memory layout...
8
by: =?big5?B?r0W84Q==?= | last post by:
Hi All C gurus: Below is a small program to print out the address of array and address of array variable: int main() { char array = "haha"; printf("array:%x\n", array); printf("&array:%x\n",...
4
by: Bob Bedford | last post by:
Hello, I've an array of array(1,2,3,4). I'd like to retrieve the values in 3 and 4 giving the values 1 and 2. How can I do that, how to search in an array of array ? in short, how to write the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.