Jump to content

[SOLVED] Get the ID of cells in a table inside a div ..


mwl707

Recommended Posts

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.

 

function confirm_allocate() {

var msg = ""

var tab = document.getElementById('visi');

var r = tab.rows.length

 

for (i=0; i<r; i++){

cc = tab.rows.cells.length

for (col=0; col<cc; col++){

x=document.getElementById('visi').rows.cells;

 

iden = x[col].className

ref =  x[col].id

 

msg += "Class =" + iden + " ///    Id =" + ref +  "\r"

}

}

alert (msg )

}

 

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  )

 

<?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 =  "<h2 align= 'center' > $jobname (Job Number $jobnumber) : Screens required : $screens </h2>"  ;

$table .= "<table id='visi' width='480px'  align='center'  cellspacing='1'  cellpadding='1'  border='1' ><tr>"  ;

 

// 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 < $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 .= "<td >$item<br> [$booked_for_job to Allocate] </td> " ;

 

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 .= "<td class='truckbox' > <div class='$class' id='$id_items' onClick='allocate(\"$booked_for_job\",\"$id_items\")'  > " ;

$table .= "$num </div> </td>"  ;

 

} ELSEIF ($booked_job === 0 ) {  // available to allocated

$class .= "g" ;

$table .= "<td class='truckbox' > <div class='$class' id='$id_items' onClick='allocate(\"$booked_for_job\",\"$id_items\")'  > " ;

$table .= "$num </div> </td>"  ;

 

} ELSE { // allocated to ANOTHER job

$class .= "a" ;

$table .= "<td class='truckbox' > <div class='$class' id='$items' > " ;

$table .= "</td> "  ;

}

 

} // while

 

$table .= "</tr>" ;

} ; // if

}; //for

 

 

$table .= "</table> " ;

 

$table .= "<table width='200px'  align='center'  cellspacing='12'  cellpadding='1'  ><tr>" ; // draw table buttons close and allocate

$table .= "</tr><tr>" ;

$table .= "<td class='truckbox' <div class='yesbutton' id='yes' onClick='confirm_allocate()' ; return false ;  >  ";

$table .= "<td class='truckbox' <div class='nobutton' id='no' onClick='hide()'  >  ";

$table .= "</tr></table> ";

 

echo $table ; // finally draw table 

 

include '../database_sql/dbclose.php' ;

 

?>

 

 

 

Link to comment
Share on other sites

Hi This is the generated HTML code

 

<h2 align= 'center' > Pontefract Racecourse (Job Number 427) : Screens required : 2 </h2>

<table id='visi' width='480px'  align='center'  cellspacing='1'  cellpadding='1'  border='1' >

<tr>

<td >i100<br> [2 to Allocate] </td>

<td class='truckbox' > <div class='i100s' id='i100s1' onClick='allocate("2","i100s1")'  >  </div> </td>

<td class='truckbox' > <div class='i100s' id='i100s2' onClick='allocate("2","i100s2")'  >  </div> </td>

<td class='truckbox' > <div class='i100sg' id='i100s3' onClick='allocate("2","i100s3")'  >  </div> </td>

<td class='truckbox' > <div class='i100sg' id='i100s4' onClick='allocate("2","i100s4")'  >  </div> </td>

</tr>

<td >i25<br> [1 to Allocate] </td>

<td class='truckbox' > <div class='i25s' id='i25s1' onClick='allocate("1","i25s1")'  >  </div> </td>

<td class='truckbox' > <div class='i25sg' id='i25s2' onClick='allocate("1","i25s2")'  >  </div> </td>

</tr>

<td >i12<br> [2 to Allocate] </td>

<td class='truckbox' > <div class='i12sg' id='i12s1' onClick='allocate("2","i12s1")'  >  </div></td>

<td class='truckbox' > <div class='i12s' id='i12s2' onClick='allocate("2","i12s2")'  >  </div> </td>

<td class='truckbox' > <div class='i12s' id='i12s3' onClick='allocate("2","i12s3")'  >  </div> </td>

<td class='truckbox' > <div class='i12sg' id='i12s4' onClick='allocate("2","i12s4")'  >  </div></td>

</tr>

</table>

 

<table width='200px'  align='center'  cellspacing='12'  cellpadding='1'  >

<tr></tr>

<tr><td class='truckbox' ><div class='yesbutton' id='yes' onClick='confirm_allocate()' ; return false ;  >  <td class='truckbox' ><div class='nobutton' id='no' onClick='hide()'  >  </tr>

</table>

 

if it helps to see the box here is the link http://www.abbeysoft.co.uk/adi/diary_booking/diary_view.php

From there you need to click 'listings date range and make sure the range includes 15th October 2009, then click Pontefract Racecourse in orange on this date.  this will display the table.

Link to comment
Share on other sites

To obtain the ids, you'll need to do something similar to what I had you do in the last thread.

 

var oTable = document.GetElementById('visi');
var cells = oTable.getElementsByTagName('div');

for(var i = 0; i < cells.length; ++i)
{
   alert("Cell id: " + cells[i].id);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.