title: get id of a cell in a table inside a div (JS and HTML)
body: <p>Hi I have a php script that draws a table subject to certain conditions. When the table is drawn it is inside a div called ‘window’  and the table is called ‘visi’ I then want to use the code below to get the id’s of each cell in the table. I can get the class name no problem but get absolutely nothing from the id. Can anyone give me an idea of what i am doing wrong?. I have tried a similar peice of code on a table that is not inside a div and it works fine.  Any help would be great and I hope the code makes sense. </p>
  
  <pre><code>function confirm_allocate() {
  var msg = ""   
  var tab = document.getElementById('visi');
  var r = tab.rows.length
  
  for (i=0; i&lt;r; i++){
  cc = tab.rows.cells.length
           for (col=0; col&lt;cc; col++){
              x=document.getElementById('visi').rows.cells;   
  
              iden = x[col].className
              ref =  x[col].id
  
              msg += "Class =" + iden + " ///    Id =" + ref +  "\r" 
           } 
  } 
  alert (msg ) 
  }
  </code></pre>
  
  <p>If it helps this is the code to draw the table (but this is called using js/ ajax after getting the information for the table  ) </p>
  
  <pre><code>&lt;?php
  
  $table = ""  ;
  include '../database_sql/dbconnect.php' ;
  include '../functions/job_details.php';
  include '../functions/check_date.php';
  include '../functions/stock_list.php' ; 
  include '../functions/allocated_on_date.php' ; 
  
  $jobdate = $_GET['jobdate'] ;
  $jobnumber = $_GET['jobnumber'] ;
  $jobname = $_GET['jobname'] ;
  
  $screens = screens_per_job($jobnumber,$size) ;
  
  $table =  "&lt;h2 align= 'center' &gt; $jobname (Job Number $jobnumber) : Screens required : $screens &lt;/h2&gt;"  ;
  $table .= "&lt;table id='visi' width='480px'  align='center'  cellspacing='1'  cellpadding='1'   border='1' &gt;&lt;tr&gt;"  ;
  
  // get stock list from DB 
  stock_list() ; 
  $len = count( $stock);
  
  $evresult = mysql_query("SELECT * FROM event WHERE jobnumber = '$jobnumber' ")  ;
  $event_row = mysql_fetch_array($evresult);
  
  for ($counter = 0; $counter &lt; $len; $counter++) {
        $item =  $stock[$counter] ;
        $items = $item . "s" ; 
        $booked_for_job = $event_row[$items] ;
        $result = mysql_query("SELECT * FROM $item ")  ;
        allocated_on_date($jobdate) ; // function 
  
           if ($booked_for_job) {   
           $count =  1 ;
           $table .= "&lt;td &gt;$item&lt;br&gt; [$booked_for_job to Allocate] &lt;/td&gt; " ;
  
                 WHILE ($row = mysql_fetch_array($result)) { ;
                 $booked_job = $screens[$item][$count]["job"] ;  // from the   allocated_on_date($jobdate)  function  
                 $description = $row['trailer_id'];
                 $class = $items ;
                 $id_items = $items . $count ;
                 $count ++ ;   
  
                          if ($booked_job == $jobnumber) {  // allocated to current job
                          $table .= "&lt;td class='truckbox' &gt; &lt;div class='$class' id='$id_items' onClick='allocate(\"$booked_for_job\",\"$id_items\")'  &gt; " ;
                          $table .= "$num &lt;/div&gt;   &lt;/td&gt;"  ;
  
                                   } ELSEIF ($booked_job === 0 ) {  // available to allocated 
                                   $class .= "g"   ;
                                      $table .= "&lt;td class='truckbox' &gt; &lt;div class='$class' id='$id_items' onClick='allocate(\"$booked_for_job\",\"$id_items\")'  &gt; " ;
                                   $table .= "$num &lt;/div&gt;   &lt;/td&gt;"  ;
  
                                                     } ELSE {    // allocated to ANOTHER job 
                                                     $class .= "a"   ;
                                                     $table .= "&lt;td class='truckbox' &gt; &lt;div class='$class' id='$items' &gt; " ;
                                                     $table .= "&lt;/td&gt; "  ;
                                                     }
  
                 } // while 
  
           $table .= "&lt;/tr&gt;" ; 
           } ; // if
  }; //for
  
  
  $table .= "&lt;/table&gt; " ;
  
  $table .= "&lt;table width='200px'  align='center'  cellspacing='12'  cellpadding='1'   &gt;&lt;tr&gt;" ; // draw table buttons close and allocate
  $table .= "&lt;/tr&gt;&lt;tr&gt;" ;
  $table .= "&lt;td class='truckbox' &lt;div class='yesbutton' id='yes' onClick='confirm_allocate()' ; return false ;  &gt;  ";
  $table .= "&lt;td class='truckbox' &lt;div class='nobutton' id='no' onClick='hide()'   &gt;  ";
  $table .= "&lt;/tr&gt;&lt;/table&gt; ";
  
  echo $table ; // finally draw table   
  
  include '../database_sql/dbclose.php' ;
  
  ?&gt;
  </code></pre>