View Full Version : need urgent help

Nov 25th, 2009, 03:30 PM
I'm a newbie to php and javascript. I want some checkbox to hide some rows of my table so i did a search and i found a few javascript codes but yet I couldn't make it work the way I wanted it. When I uncheck a checkbox ONLY the first table rows get hidden, the other tables don't? can't I ID some rows? Please I need help :(

My javascript code is:

<script type="text/javascript"><!--
function showHideTR(idx,vis) {
var tbl,row;
if(document.getElementById && document.getElementsByTagName) {
tbl = document.getElementById('tbl');
if(!tbl || (idx >= tbl.getElementsByTagName('tr').length)) return;
row = tbl.getElementsByTagName('tr')[idx];
} else if(document.all && document.all.tags) { // IE4 support
tbl = document.all.tbl;
if(!tbl || (idx >= tbl.all.tags('tr').length)) return;
row = tbl.all.tags('tr')[idx];
if(row) {
if(!vis) {
row.style.display = 'none';
} else {
// conditional compilation to hide the try-catch blocks from IE4
/*@cc_on @if([email protected]_jscript || (@_jscript_version >= 5)) @*/
try {
row.style.display = 'table-row';
} catch(e) {
row.style.display = 'block';
/*@elif(@_jscript_version < 5)
row.style.display = 'block'; // for IE4
@end @*/
function getStyle(el,styleProp)
var x = (typeof(el)=='string')?document.getElementById(el):el;
if (x.currentStyle)
var y = x.currentStyle[styleProp];
else if (window.getComputedStyle)
var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
return y;
window.onload = function() {
if(!document.getElementsByTagName) return;
var tds = document.getElementsByTagName('td');
for(var i=0;i<tds.length;i++) {
tds[i].onclick = function() {
alert(this.parentNode.tagName+' = display : '+getStyle(this.parentNode,'display')+
'\n'+this.tagName+' = display : '+getStyle(this,'display'));
// -->

<!-- <script type="text/javascript">
function showHideTR(idx,vis) {
var tbl,val;
val = (!vis)?'none':((document.defaultCharset && !window.home)?'block':
if(document.getElementById && document.getElementsByTagName) {
tbl = document.getElementById('tbl');
if(idx >= tbl.getElementsByTagName('tr').length) return;
tbl.getElementsByTagName('tr')[idx].style.display = val;
} else if(document.all && document.all.tags) { // IE4 support
tbl = document.all.tbl;
if(idx >= tbl.all.tags('tr').length) return;
tbl.all.tags('tr')[idx].style.display = val;
</script> -->

My option tags:

<form action="#" onsubmit="return false;">
<li2><label for="cb0"><input type="checkbox" id="cb0" checked="checked"
onclick="showHideTR(0,this.checked);"> Blah Blah</label></li>
<li2><label for="cb1"><input type="checkbox" id="cb1" checked="checked"
onclick="showHideTR(1,this.checked);"> Blah Blah2</label></li>
<li2><label for="cb2"><input type="checkbox" id="cb2" checked="checked"
onclick="showHideTR(2,this.checked);"> Blah Blah3</label></li>
<li2><label for="cb3"><input type="checkbox" id="cb1" checked="checked"
onclick="showHideTR(3,this.checked);"> Blah Blah4</label></li>

My php page:


$host = "localhost"; // your host name
$username = "blah blah"; // your user name to access MySql
$password = "blah blah"; // your password to access MySql
$database = "blah blah"; // The name of the database
$no = $_POST["sureno"];

//$link = mysql_connect($host,$username,$password);
if (!$link = @mysql_connect($host,$username,$password,true))
{die('Could not connect:'. mysql_error()); }

@mysql_query("SET NAMES 'latin5'");
@mysql_select_db($database) or die( "Unable to select database");
$sql="SELECT *
FROM blah blah
WHERE sure = '$no'
ORDER BY 'id'";

$result = mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());

echo "<TABLE width=50% align=center cellpadding=0 cellspacing=0 id='tbl' summary='demonstration'> <tr>";
echo "<td bgcolor='dfdfdf' ><font face='arial,verdana,helvetica' color='#000000' size='3'>blah blah</font></td>";
echo "<td bgcolor='C0C0C0' ><font face='arial,verdana,helvetica' color='#FF0000' size='4'>" . $row['AB'] ."</font></td></tr>";
echo "<tr><td bgcolor='dfdfdf' ><font face='arial,verdana,helvetica' color='#000000' size='3'>blah blah</font></td>";
echo "<td bgcolor='dfdfdf'>&nbsp;<font face='arial,verdana,helvetica' color='#0080C0' size='2'>". $row['TR'] ."</font></td></tr>";
echo "<tr><td bgcolor='dfdfdf' ><font face='arial,verdana,helvetica' color='#000000' size='3'>blah blah</font></td>";
echo "<td bgcolor='dfdfdf' id='cb0'>&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='3'>". $row['ML'] ."</font></td></tr>";



Philip M
Nov 25th, 2009, 04:46 PM
Please help us to help you by following the posting guidelines and wrapping your code in [code] tags. This means use the octothorpe or # button on the toolbar which will insert opening [ code ] and closing [ /code ] tags - omit the spaces. You can (and should) edit your previous post.

See also http://www.codingforums.com/showthread.php?t=2090 Para. 3.

Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. You can (and should) edit it to make it more meaningful.

The <!-- and //--> comment (hiding) tags have not been necessary since IE3. If you see these in some published script it is a warning that you are looking at ancient and perhaps unreliable code. Likewise the references to IE4 support.

Old Pedant
Nov 25th, 2009, 09:34 PM
Your PHP code is creating ILLEGAL HTML.

Each row (record) you fetch from the DB creates a new <TABLE> but you *never* create any </TABLE> to match.

The code is also using the deprecated <font> tag which you really woudn't need at all if you'd use CSS. But at least that's not illegal HTML.

In any case, instead of showing us your PHP code, you should show us the HTML code that it generates. You do that by bringing up the page in your browser and then using VIEW==>SOURCE (or PAGE SOURCE, depending on browser).