Jump to content

'style' is null or not an object


earhear

Recommended Posts

Hi need a bit of help here.  I encountered the error: 'style' is null or not an object at the row: "cels[col_no].style.display=stl;"  How do I solve this?

 

<!-- Script to hide columns -->

<table border="1">

<!--

<?php $rowlength=pg_num_rows($rs_latest_inc);

echo 'rows.length='.$rowlength.'<br>';?>

-->

    <script type="text/javascript">

      function show_hide_column(col_no, do_show)

      {

        var stl;

        if (do_show) stl = 'block'

        else        stl = 'none';

 

        var tbl  = document.getElementById('table_hide');

        var rows = tbl.getElementsByTagName('tr');

 

        for (var row=0; row<10;row++)

        {

          var cels = rows[row].getElementsByTagName('td')

          cels[col_no].style.display=stl;

        }

      }

    </script>

<script>

</script>

<tr>

<td>

<img src="Images/link.gif" width="10" height="10" onClick="javascript:show_hide_column(1, true)">Show "Pod Status"<br>

<img src="Images/link.gif" width="10" height="10" onClick="javascript:show_hide_column(1, false);">Hide "Pod Status"<br>

</td>

</tr>

</table>

<!-- End of Script -->

Link to comment
Share on other sites

Thanks for showing interest.  This script is to show/hide columns on my table.  I inserted this script into my own code.  Actually, I got this code from somewhere else on the web but I couldn't remember where.  Sorry bout that.  This is the original code:

 

==============================================================================

<html>

<head>

<script>

 

  function show_hide_column(col_no, do_show) {

 

    var stl;

    if (do_show) stl = 'block'

    else        stl = 'none';

 

    var tbl  = document.getElementById('table_hide');

    var rows = tbl.getElementsByTagName('tr');

 

    for (var row=0; row<rows.length;row++) {

      var cels = rows[row].getElementsByTagName('td')

      cels[col_no].style.display=stl;

    }

  }

</script>

 

</head>

<body>

<form>

<img src="Images/link.gif" width="10" height="10" onClick='javascript:show_hide_column(1, true);'>Show "Pod Status"<br>

<img src="Images/link.gif" width="10" height="10" onClick='javascript:show_hide_column(1, false);'>Hide "Pod Status"<br>

</form>

 

<table id='table_hide' border=1>

  <tr><td>  1</td><td>  one</td><td>    un</td><td>    eins</td></tr>

  <tr><td>  2</td><td>  two</td><td>  deux</td><td>    zwei</td></tr>

  <tr><td>  3</td><td> three</td><td>  trois</td><td>    drei</td></tr>

  <tr><td>  4</td><td>  four</td><td>quattre</td><td>    vier</td></tr>

  <tr><td>  5</td><td>  five</td><td>  cinq</td><td>fünf</td></tr>

  <tr><td>  6</td><td>  six</td><td>    six</td><td>    sechs</td></tr>

</table>

==============================================================================

Link to comment
Share on other sites

Hope you won't freak out when you see my code.  Sorry about the mess.  I inserted the javascript into this code.  Look for the comment "<!-- Script to hide columns -->".  When I inserted the script into my php codes, i get an error that says, "style' is null or not an object" at the line "cels[col_no].style.display=stl;".

 

============================================================

<?php

    include("start.php");

    include("function.php");

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>2.2 Pre-Inspection</title>

<link href="style.css" rel="stylesheet" type="text/css">

</head>

<body>

<form name="preinsp_form" method="GET">

<table width="96%">

    <tr>

      <td height="44" colspan="2" align="center" class="header">Smif Pod & Smart Tag Tracking System</td>

    </tr>

    <tr>

      <td height="23" colspan="2" align="center" class="main_table_header">2.2 Pre-Inspection</td>

    </tr>

    <tr>

      <td valign="top"><!--Floating Menu Table-->

        <?php include("menu.htm");?>

      </td><!--End of Floating Menu Table-->

        <td width="80%" height="485" valign="top">

 

<!-- Script to hide columns -->

<table border="1">

<!--

<?php $rowlength=pg_num_rows($rs_latest_inc);

echo 'rows.length='.$rowlength.'<br>';?>

-->

    <script type="text/javascript">

      function show_hide_column(col_no, do_show)

      {

        var stl;

        if (do_show) stl = 'block'

        else        stl = 'none';

 

        var tbl  = document.getElementById('table_hide');

        var rows = tbl.getElementsByTagName('tr');

 

        for (var row=0; row<rows.length;row++)

        {

          var cels = rows[row].getElementsByTagName('td')

          cels[col_no].style.display=stl;

        }

      }

    </script>

<script>

//        var rowlength=<?php $rowlength;?>;

//        document.write('this is the row length in js=');       

//        document.write(rowlength);

</script>

<tr>

<td>

<img src="Images/link.gif" width="10" height="10" onClick="javascript:show_hide_column(1, true)">Show "Pod Status"<br>

<img src="Images/link.gif" width="10" height="10" onClick="javascript:show_hide_column(1, false);">Hide "Pod Status"<br>

</td>

</tr>

</table>

<!-- End of Script -->

 

            <table id="table_hide" width="888" border="1">

            <tr>* Pod details: Pod S/N, Cass S/N, Podbase S/N, Tag S/N</tr>

            <tr><td height="40"> </td>

                <td><strong>Pod Details</strong></td>

                <td><strong>Pod Defect</strong></td>

                <td><strong>Cassette Status</strong></td>

                <td><strong>Podbase Status</strong></td>

                <td><strong>Smart Tag Status</strong></td>

                <td><strong>Updated Time</strong></td>

                <td><strong>Updated By</strong></td>

                <td><strong>Sent Time</strong></td>

                <td><strong>Sent By</strong></td>

                <td><strong>Received Time</strong></td>

                <td><strong>Received By</strong></td>

                <td><strong>Remarks</strong></td>

          </tr>

            <?php

                //Displays all the latest records in the pod database where status="Pre-Inspection"

                $sql_latest_inc="SELECT * FROM pod WHERE pod_status='Pre-Inspection'";

                $rs_latest_inc=pg_query($db_link, $sql_latest_inc) or die(pg_result_error());

 

                //Checkbox arrays

                $cb = 0;   

               

                //Start of loop to display all available records

                while ($row_latest_inc=pg_fetch_assoc($rs_latest_inc))

                  {

            ?>

              <tr>

                <td>

                    <input name="checkbox<?php echo $cb;?>" type="checkbox" id="checkbox<?php echo $cb; ?>" value="<?php echo $row_latest_inc['pod_sn_time']; ?>">

                </td>

                <td>

                    <?php echo $row_latest_inc['pod_sn'];?>, <?php echo $row_latest_inc['cass_sn'];?>, <?php echo $row_latest_inc['podbase_sn'];?>, <?php echo $row_latest_inc['tag_sn'];?>

                </td>

                <input type="hidden" name="pod_status" value="<?php echo $row_latest_inc['pod_status'];?>">

                <td>

                    <?php include ("pod_defect.php");?>

                <td>

                    <div>

                        <p align="left"><a href="javascript:void(0);" onClick="window.open('cass_defect.php?pod_sn_time=<?php echo $row_latest_inc['pod_sn_time'];?>','pop_up','resizable=yes,scrollbars=yes,height=800,width=450')" >Cassette Defect Details <img src="Images/link.gif" width="10" height="10"></a></p>

                        <p align="left"> </p>

                    </div>

                    <div>Proceed?

                        <input name="cass_stat<?php echo $cb;?>" type="checkbox" id="cass_stat<?php echo $cb;?>" value="<?php echo "Proceed";?>">

                    </div>

                </td>

                <td>

                    <div>

                        <p align="left"><a href="javascript:void(0);" onClick="window.open('pb_defect.php?pod_sn_time=<?php echo $row_latest_inc['pod_sn_time'];?>','pop_up','resizable=yes,scrollbars=yes,height=800,width=450')" >Podbase Defect Details <img src="Images/link.gif" width="10" height="10"></a></p>

                        <p align="left"> </p>

                    </div>

                    <div>Proceed?

                        <input name="pb_stat<?php echo $cb;?>" type="checkbox" id="pb_stat<?php echo $cb;?>" value="<?php echo "Proceed";?>">

                    </div>

                </td>

                <td>

                    <div>

                        <p align="left"><a href="javascript:void(0);" onClick="window.open('tag_defect.php?pod_sn_time=<?php echo $row_latest_inc['pod_sn_time'];?>','pop_up','resizable=yes,scrollbars=yes,height=800,width=450')" >Smart Tag Defect Details <img src="Images/link.gif" width="10" height="10"></a></p>

                        <p align="left"> </p>

                    </div>

                    <div>Proceed?

                        <input name="tag_stat<?php echo $cb;?>" type="checkbox" id="tag_stat<?php echo $cb;?>" value="<?php echo "Proceed";?>">

                    </div>

                </td>

                <td><?php echo $row_latest_inc['pod_update_time'];?></td>

                <td><?php echo $row_latest_inc['pod_update_by'];?></td>

                <td><?php echo $row_latest_inc['pod_sent_time'];?></td>

                <td><?php echo $row_latest_inc['pod_sent_by'];?></td>

                <td><?php echo $row_latest_inc['pod_recv_time'];?></td>

                <td><?php echo $row_latest_inc['pod_recv_by'];?></td>

                <td><?php echo $row_latest_inc['pod_remarks'];?></td>

                <?php

                $cb++;

            }

            ?> <!--End of while loop-->

              </tr>

      </table>

          <table width="100%">

            <tr>

            <td>

                <input type="submit" class="button" name="Proceed" value="Proceed" id="Proceed">

            </td>

            </tr>

 

 

</table></td>

    </tr>

    </form>

 

<?php

    // Change pod_status of current pod_sn_time to '-Pre-Inspection' and add a duplicate record (but different pod_sn_time) with pod_status='Pre-Clean' or 'Disposition'

    // If Proceed button active, start this

    $count=pg_num_rows($rs_latest_inc);

   

    if(isset($_GET['Proceed']))

    {

        for($i=0;$i<$count;$i++)

        {

            $proceed_id = 'checkbox'.$i;

            $pod_stat = 'pod_stat'.$i;

            $cass_stat = 'cass_stat'.$i;

            $pb_stat = 'pb_stat'.$i;

            $tag_stat = 'tag_stat'.$i;

            $sql_chkbox1 = "UPDATE pod SET pod_status='-Pre-Inspection', pod_sn_time='-".$_GET[$proceed_id]."' WHERE pod_sn_time='".$_GET[$proceed_id]."'";

            $rs_chkbox1 = pg_query($db_link, $sql_chkbox1) or die(pg_result_error());

            echo 'sql_chkbox1='.$sql_chkbox1.'<br>';

           

            $sql_chkbox2 = "SELECT * FROM pod WHERE pod_sn_time='-".$_GET[$proceed_id]."'";

            $rs_chkbox2 = pg_query($db_link, $sql_chkbox2) or die(pg_result_error());

            $row_chkbox2 = pg_fetch_assoc($rs_chkbox2);

            echo 'sql_chkbox2='.$sql_chkbox2.'<br>';

           

            //only execute this if pod_sn NOT null

            if(($row_chkbox2['pod_sn']!="")&&($_GET[$pod_stat]=="Proceed")&&($_GET[$cass_stat]=="Proceed")&&($_GET[$pb_stat]=="Proceed")&&($_GET[$tag_stat]=="Proceed"))

                {

                    $sql_chkbox = "INSERT INTO pod(pod_sn_time, pod_sn, tag_holder_sn, cass_sn, podbase_sn, tag_sn, pod_chd_type, pod_brand, pod_mat_code, pod_cat, pod_status, pod_clean, pod_update_time, pod_update_by, pod_sent_time, pod_sent_by, pod_recv_time, pod_recv_by, pod_request_time, pod_request_by, pod_issue_time, pod_issue_by, pod_defect, cass_defect, pb_defect, tag_defect, pod_clean_tool, pod_remarks) VALUES (

                          '".$row_chkbox2['pod_sn'].$pod_update_time."',

                          '".$row_chkbox2['pod_sn']."',

                          '".$row_chkbox2['tag_holder_sn']."',

                          '".$row_chkbox2['cass_sn']."',

                          '".$row_chkbox2['podbase_sn']."',

                          '".$row_chkbox2['tag_sn']."',

                          '".$row_chkbox2['pod_chd_type']."',

                          '".$row_chkbox2['pod_brand']."',

                          '".$row_chkbox2['pod_mat_code']."',

                          '".$row_chkbox2['pod_cat']."',

                          'Pre-Clean',

                          '".$row_chkbox2['pod_clean']."',

                          '".$pod_update_time."',

                          '".$pod_update_by."',

                          '".$row_chkbox2['pod_sent_time']."',

                          '".$row_chkbox2['pod_sent_by']."',

                          '".$row_chkbox2['pod_recv_time']."',

                          '".$row_chkbox2['pod_recv_by']."',

                          '".$row_chkbox2['pod_request_time']."',

                          '".$row_chkbox2['pod_request_by']."',

                          '".$row_chkbox2['pod_issue_time']."',

                          '".$row_chkbox2['pod_issue_by']."',

                          '".$row_chkbox2['pod_defect']."',

                          '".$row_chkbox2['cass_defect']."',

                          '".$row_chkbox2['pb_defect']."',

                          '".$row_chkbox2['tag_defect']."',

                          '".$row_chkbox2['pod_clean_tool']."',

                          '".$row_chkbox2['pod_remarks']."'

                          )";

 

                    $rs_chkbox = pg_query($db_link, $sql_chkbox) or die(pg_result_error());

                    echo 'sql_chkbox='.$sql_chkbox.'<br>';

                    pg_free_result($rs_chkbox);

                }

            else if(($row_chkbox2['pod_sn']!="")&&(($_GET[$pod_stat]=="")||($_GET[$cass_stat]=="")||($_GET[$pb_stat]=="")||($_GET[$tag_stat]=="")))

                {

                    $sql_chkbox = "INSERT INTO pod(pod_sn_time, pod_sn, tag_holder_sn, cass_sn, podbase_sn, tag_sn, pod_chd_type, pod_brand, pod_mat_code, pod_cat, pod_status, pod_clean, pod_update_time, pod_update_by, pod_sent_time, pod_sent_by, pod_recv_time, pod_recv_by, pod_request_time, pod_request_by, pod_issue_time, pod_issue_by, pod_defect, cass_defect, pb_defect, tag_defect, pod_clean_tool, pod_remarks) VALUES (

                          '".$row_chkbox2['pod_sn'].$pod_update_time."',

                          '".$row_chkbox2['pod_sn']."',

                          '".$row_chkbox2['tag_holder_sn']."',

                          '".$row_chkbox2['cass_sn']."',

                          '".$row_chkbox2['podbase_sn']."',

                          '".$row_chkbox2['tag_sn']."',

                          '".$row_chkbox2['pod_chd_type']."',

                          '".$row_chkbox2['pod_brand']."',

                          '".$row_chkbox2['pod_mat_code']."',

                          '".$row_chkbox2['pod_cat']."',

                          'Disposition',

                          '".$row_chkbox2['pod_clean']."',

                          '".$pod_update_time."',

                          '".$pod_update_by."',

                          '".$row_chkbox2['pod_sent_time']."',

                          '".$row_chkbox2['pod_sent_by']."',

                          '".$row_chkbox2['pod_recv_time']."',

                          '".$row_chkbox2['pod_recv_by']."',

                          '".$row_chkbox2['pod_request_time']."',

                          '".$row_chkbox2['pod_request_by']."',

                          '".$row_chkbox2['pod_issue_time']."',

                          '".$row_chkbox2['pod_issue_by']."',

                          '".$row_chkbox2['pod_defect']."',

                          '".$row_chkbox2['cass_defect']."',

                          '".$row_chkbox2['pb_defect']."',

                          '".$row_chkbox2['tag_defect']."',

                          '".$row_chkbox2['pod_clean_tool']."',

                          '".$row_chkbox2['pod_remarks']."'

                          )";

 

                    $rs_chkbox = pg_query($db_link, $sql_chkbox) or die(pg_result_error());

                    echo 'sql_chkbox='.$sql_chkbox.'<br>';

                    pg_free_result($rs_chkbox);                   

                }

        }

 

        //if successful redirect to preinsp.php

        if($rs_chkbox1)

        {

            echo "<meta http-equiv=\"refresh\" content=\"0;URL=preinsp.php\">";

        }

    }

?>

 

 

 

    <tr>

      <td colspan="2"><div class="bottomtext" align="center"><?php echo $footer; ?></div></td>

    </tr>

</body>

</html>

 

============================================================

Link to comment
Share on other sites

If the issue with your script is on the PHP end and it seems like it must be; since I tested your JavaScript code with out the PHP and it worked fine; you need to post this topic in this forum:

 

http://www.phpfreaks.com/forums/index.php/board,1.0.html

 

One problem, at a glance is - because I did not review all of you PHP; your not using single or double quotes around some of the variables you are echoing - that could be causing some of your problems.

 

PS: Please use code "#" button, in thread tools; when posting your code on these forums. It makes it much easier to read and replicate your code issue this way.

Link to comment
Share on other sites

because of the way javascript arrays work with the first array element being 0 instead of 1, the call to the js routine below  will actually be referring to the second column, not the first. In your 'table_hide' table shown below, the first tr has no td's! Which means that that row will be interpreted to have at most one td.  Which means that your reference to 'show_hide_column(1, true)' will fail because there is only  a zero array element - there is no '1' element.

<img src="Images/link.gif" width="10" height="10" onClick="javascript:show_hide_column(1, true)">Show "Pod Status"

 

 <table id="table_hide" width="888" border="1">
            <tr>* Pod details: Pod S/N, Cass S/N, Podbase S/N, Tag S/N</tr>
            <tr><td height="40"> </td>

the below does not exist because of your first tr in your 'table_hide' table!

cels[1].style.display=stl;

 

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.