Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 14th, 2012  |  syntax: None  |  size: 1.51 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. JSON how find another value at the same index from a value in Javascript Object
  2. while ($Row = mysql_fetch_array($params))
  3.     {
  4.         $jsondata[]= array('adc'=>$Row["adc"],
  5.                            'adSNU'=>$Row["adSNU"],
  6.                            'adname'=>$Row["adname"],
  7.                            'adcl'=>$Row["adcl"],
  8.                            'adt'=>$Row["adt"]);
  9.     };
  10.  
  11. echo json_encode(array("Ships" => $jsondata));
  12.        
  13. if (ajaxRequest.readyState==4 && ajaxRequest.status==200 || ajaxRequest.status==0)
  14.         {
  15.             WShipsObject = JSON.parse(ajaxRequest.responseText);
  16.  
  17.             var eeWShips = document.getElementById("eeWShipsContainer");
  18.  
  19.                 for (i=0;i<WShipsObject.Ships.length;i++)
  20.                 {
  21.                     newElement = WShipsObject.Ships;
  22.                     newWShip = document.createElement("div");
  23.  
  24.                     newWShip.id = newElement[i].adSNU;
  25.                     newWShip.class = newElement[i].adc;
  26.  
  27.                     eeWShips.appendChild(newWShip);
  28.  
  29.  
  30.                 } // end for
  31.  
  32.         }// If
  33.        
  34. $(".wShip").click(function(){
  35.  
  36.     var test1 = $.inArray(this.id, newElement.test);
  37.     var test2 = $.inArray(this.id, WShipsObject);
  38.  
  39.     //alert(test1+"n"+test2+"n"+this.id);
  40.  
  41. });
  42.        
  43. $(".wShip").click(function(){
  44.   var id = $(this).id;
  45.   var result;
  46.  
  47.   WShipsObject.Ships.each(function(data) {
  48.     if(data.adSNU == id) {
  49.       result = data;
  50.     }  
  51.   });
  52.  
  53.   console.log(result);
  54. }
  55.        
  56. newWShip.key = i;
  57.        
  58. var key = this.key;
  59. var adt = WShipsObject.Ships[key].adt;