By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

Values passed from javascript

100+
P: 178
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
Share this Question
Share on Google+
3 Replies


hsriat
Expert 100+
P: 1,654
Make three hidden inputs, one for each value you need to pass, and change their values by JavaScript.
Aug 14 '08 #2

100+
P: 178
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
Expert 100+
P: 1,654
See what's being posted.
[php]<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";
?>[/php]
Aug 14 '08 #4

Post your reply

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