473,804 Members | 2,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pass a javascript array to php file

82 New Member
Hi,
Expand|Select|Wrap|Line Numbers
  1. <?
  2. #cd.php
  3. echo "<input type='text' name='text1' id='text1' onchange=\"return_value()"\ /><br></br>";
  4. ?>
  5.  
Javascript file
Expand|Select|Wrap|Line Numbers
  1. var xmlHttp;
  2.  function return_value() {
  3.  var x=document.getElementById('text1').value;
  4.  xmlHttp = GetXmlHttpObject();
  5.  if(xmlHttp == null) {
  6.  alert("Your browser does not support ajax");
  7.  return;
  8.  }
  9.  var url="ab.php";
  10.  url=url+"?x="+x;
  11.  xmlHttp.open("GET",url,true);
  12.   xmlHttp.send(null);
  13.  xmlHttp.onreadystatechange = StateChanged;
  14.  function StateChanged() {
  15.  if(xmlHttp.readyState == 4) {
  16.  var y=new Array();
  17. y= xmlHttp.responseText;
  18.  }
  19.  }
the file ab.php returns an array to the javascript file, how can i pass this array 'y' to the php cd.php file
Jan 20 '09 #1
12 9013
Dormilich
8,658 Recognized Expert Moderator Expert
I guess you have to use a serializer for that. JSON and WDDX are the ones I've heard of (both work in Javascript and PHP)

in the javascript code line 16 is unnecessary, your array (y) will be replaced by the return string (responseText).
Jan 20 '09 #2
sarega
82 New Member
ok...can you just give an example of how to serialize it??
Jan 20 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
so far I've only done WDDX. JSON might be more suitable for you. explanations and example you can find here:
Jan 20 '09 #4
sarega
82 New Member
ok will try that now...thank you
Jan 20 '09 #5
sarega
82 New Member
for serializing at the javascript and deserializing at the php side, can both the javascript n php be in different files??
Jan 20 '09 #6
Dormilich
8,658 Recognized Expert Moderator Expert
@sarega
yes...???

PHP is run on the server, JS in the browser, that's two different locations. so why would you have them in the same file? (besides the fact that serialization originates from transfering complex data between system)
Jan 20 '09 #7
acoder
16,027 Recognized Expert Moderator MVP
Instead of trying to pass an array, pass something that the server-side script will recognise, e.g. "val=1&val=2&va l=3" (rather like how checked checkbox values are passed).
Jan 21 '09 #8
sarega
82 New Member
I cannot reload the page, if I did then the values that are entered in the text boxes will be lost...
Jan 22 '09 #9
Dormilich
8,658 Recognized Expert Moderator Expert
@sarega
that's just a matter of correctly setting the text boxes' default values.
Jan 22 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
6793
by: Nath | last post by:
Please help!? I am new to writing html, javascript, pretty new to MySQL but quite proficient at writing Perl and i'm a quick learner. I am building a database driven website and i am a little stuck: I have page of results obtained from a MySQL query presented as a table (the first column having checkboxes for each of the rows in the table, and all having the name "seqs"). I have set up a javascript (connected to a "toggle all" checkbox)...
5
3151
by: Seeker | last post by:
Newbie question here... I have a form with some radio buttons. To verify that at least one of the buttons was chosen I use the following code ("f" is my form object) : var btnChosen; for (count = 0; count <= 1; count++) { if (eval(f.RadioButtons.checked)) { btnChosen = true; }
4
13394
by: Sunny | last post by:
Hi, I am at present working on a jsp page which has a single text field. Upon entering a value in the field, i am trigerring an onChangeEvent() which calls a method of javascript. I am also dynamically creating an array in the jsp page and want to pass this array (by reference) to the javascript function. All I want to do in the javascript function is to check whether the input value matches with any of the array elements. However, i have...
2
6451
by: Augusto Cesar | last post by:
Hello people. How can I Pass ASP Array variable to Javascript; I´m to trying this: <script language="JavaScript"> var x = new Array(10);
10
2518
by: Sean Dockery | last post by:
I have the following HTML file that I've been using for testing... <html> <head> <script type="text/javascript"> <!-- function handleWindowLoad() { var items = ; for (var i = 0; i < 11; i++) { items = "item" + (i + 1);
2
1634
by: André | last post by:
Hi, I have to pass a lot of variables from vb.net to javascript using client callback. the problem is that there are single variables, but also arrays with differents indexes. I have two questions: 1) is this technology made for passing a lot of variables or in fact only for one? 2) does it exist a esier way to pass the values and to recover them in javascript?
1
5236
by: thomas_okken | last post by:
I'm working on a little C# DLL that will let me capture audio from within Internet Explorer. The idea is that the C# object, once it is recording, will periodically invoke a JavaScript callback, which will handle the audio somehow. The JavaScript callback is a simple function, which I pass to the C# object during its initialization; I then invoke the JavaScript callback using theCB.GetType().InvokeMember("", BindingFlags.InvokeMethod,...
4
4344
by: IRC | last post by:
hey, i am pretty new on javascript as well as PHP, Hey, anyone can you help me, how to pass the javascript array value to php page......... i want to retrieve the values which are arrayed on "selectedValues" from next page for php variable this is my javascript code saved on "sendValue.js" file, <script> function updateRecordEntry(requestValue){
1
1532
by: helraizer1 | last post by:
Hi all, I have a photography page on my website, I have pictures on the page (obviously) but the file names are stored and loaded in Javascript, in an array. var pic = new Array("./images/under1.png","./images/anemon.png","./images/arrow.png", "./images/babymoray.png","./images/grouper.png","./images/meridian.png", "./images/grouper1.png","./images/moray.png", "./images/morayeel.png", "./images/toitle.png", "./images/triggerfish.png",...
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10599
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10346
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10090
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9173
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.