473,324 Members | 2,370 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,324 software developers and data experts.

Values passed from javascript

178 100+
Hi, I have a javascript function that is definately passing three values to php. For some reason my javascript is not working as planned. Here is the javascript that passes the values.

Expand|Select|Wrap|Line Numbers
  1. function render() {
  2.     alert(g_objName);
  3.     var arr = document.getElementsByTagName("div");
  4.     var data = {
  5.         'result[]' : [],
  6.         'xReturnValue[]': [],
  7.         'yReturnValue[]' : []
  8.         };
  9.  
  10.     for(var i = 0; i < arr.length; i++)
  11.         {
  12.         var xReturnValue = -10;
  13.         var yReturnValue = -5;
  14.         for(var elem = arr[i];elem != null;elem = elem.offsetParent)
  15.             {
  16.             xReturnValue += elem.offsetLeft;
  17.                yReturnValue += elem.offsetTop;
  18.  
  19.                }
  20.                alert(arr[i].innerHTML);
  21.                var result = arr[i].innerHTML;
  22.         data['result[]'].push(result);
  23.         data['xReturnValue[]'].push(xReturnValue);
  24.         alert(xReturnValue);
  25.         data['yReturnValue[]'].push(yReturnValue);
  26.         alert(yReturnValue);
  27.         }
  28.     $.post("render.php",data);
  29.     // this bit of code is using jquery 
  30. }
Above I am passing three values, result, xReturnValue and yReturnValue. Heres the php code I am using.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require "config.php";
  3. if (strtoupper($_SERVER['REQUEST_METHOD']) !== 'GET') {
  4.   foreach($_POST['result'] as $n=>$result){
  5.     $xReturnValue = $_POST['xReturnValue'][$n];
  6.     $yReturnValue = $_POST['yReturnValue'][$n];
  7.     //do what you want with the data
  8.     $q = mysql_query("update object set xpos='$xReturnValue', ypos='$yReturnValue' where object_name = '$result'");
  9.   }
  10. }
  11. ?>
The purpose of the php is to update the specified record with new x and y values where result = object_name. At present the php does not make any changes to the db at when executed.
Aug 14 '08 #1
3 1061
hsriat
1,654 Expert 1GB
Make three hidden inputs, one for each value you need to pass, and change their values by JavaScript.
Aug 14 '08 #2
cleary1981
178 100+
I dont understand. I tried using a simple POST methon before but the problem I was having was that only certain objects were getting updated. I thought using jquery would eliminate this.
Aug 14 '08 #3
hsriat
1,654 Expert 1GB
See what's being posted.
[php]<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";
?>[/php]
Aug 14 '08 #4

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

Similar topics

5
by: TG | last post by:
Dear PHP Group, I have two forms that are used to collect user information. The first one takes user inputted values such as fullname, city, address etc. I want these values to display in the...
1
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
2
by: RootShell | last post by:
Hello First of all i know that PHP is a server side, and JavaScript is a Client side programming language, but i need to know if there is any way i can add the variable "countDownInterval" from...
2
by: foldface | last post by:
Hi Pardon the vague-ness, I mean the ?name=value stuff in the URL. Can you set this within javascript on a page such that when an asp.net button is clicked then these values are passed as params?...
3
by: drec | last post by:
I am creating a search box that the user types a value in, and then this gets passed to another page called search.php I would like to be able to pass these values through the URL, but I cant...
5
by: Priya | last post by:
Hey all, I have some values in the database which has to retrieved and then passed on to some functions in the javascript. The javascript file is a separate file. I have included it in the aspx...
1
by: PraveenAnekalmat | last post by:
Hi everyone, I'm using anchor within the for loop which means the number of anchors(links) dynamically varies. Within the anchor i'm calling one javascript function and passing the dynamic value...
5
by: mwpclark | last post by:
I have javascript code which passes select input form field values in Firefox and Opera but it does not seem to work in IE7. This form runs a search, and the search results page has the same form...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.