0

I have the following code that is supposed to make the cells int the table resizeable, and the check boxes at the bottom of the page when unchecked delete the table cell. (the check boxes work but the table doesn't resize). This was previously reported as a duplicate post that is located here Uncaught TypeError: Cannot read property 'lastChild' of null

but its not. If anyone can help me with two problems I would be greatful. I am .Net developer and don't know much about Javascript so can you please be as detailed as possible.

  1. The table cells don't resize
  2. If you get them to resize, can you change the code to have a 4 cell table with top left, top right, bottom left and bottom right.

Im so lost I would appreciate any help. The working product is located here: https://jsfiddle.net/18k3umpp/3/

FYI: I also tried putting the javascript right before the tag.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <title>Home</title>
        <link href="jquery-ui.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="jquery-ui.js"></script>
        <style type="text/css">
            html {
                height: 100%;
            }

            body {
                height: 100%;
            }

            table {
                width: 100%;
                height: 90%;
            }

            table td {
                text-align: center;
                border: 1px solid black;
            }

            #views-container {
                height: 10%;
            }
        </style>

        <script type="text/javascript">
            /**
             * Created by yako on 1/25/16.
             */
            var tds = document.getElementsByTagName('td');
            var inputs = document.getElementsByTagName('input');
            var rows = document.getElementsByTagName('tr');

            console.log(inputs);
            console.log(tds);
            var changeView = function () {

                for (var i = 0; i < inputs.length; i++) {
                    if (!inputs[i].checked) {
                        if (tds[i].style.display !== 'none') tds[i].style.display = 'none';
                    } else {
                        if (tds[i].style.display === 'none') tds[i].style.display = '';
                    }
                }

                if (!inputs[0].checked && !inputs[1].checked) rows[0].style.display = 'none';
                else rows[0].style.display = '';

                if (!inputs[2].checked) rows[1].style.display = 'none';
                else rows[1].style.display = '';

            };

            changeView();



            $(window).on("load resize", function () {

                var windowWidth = $(window).width();
                var windowHeight = $(window).height();
                var v1Width = $("#v1").width()


                $("#v1").resizable({
                    minWidth: 50,
                    maxWidth: windowWidth - 80,
                    maxHeight: windowHeight * (.83),
                    handles: "e, s"
                }).on("resize", function () {

                    if (v1Width == $("#v1").width()) {
                        $("#v2").height(0)
                    }
                    v1Width = $("#v1").width()
                });

                $("#v2").resizable({
                    maxHeight: windowHeight * (.83),
                    handles: "s"
                }).on("resize", function () {
                    $("#v1").height(0)
                });

            });
        </script>

    </head>

    <body>
        <table>
            <tr>
                <td id="v1">View 1</td>

                <td id="v2">View 2</td>
            </tr>

            <tr>
                <td colspan="2">View 3</td>
            </tr>
        </table>
        <div id="views-container">
            <input type="checkbox" checked="checked" onclick="changeView()">
            <label>View 1</label>
            <input type="checkbox" checked="checked" onclick="changeView()">
            <label>View 2</label>
            <input type="checkbox" checked="checked" onclick="changeView()">
            <label>View 3</label>
        </div>
    </body>
</html>
Community
  • 1
  • 1
RittenRA
  • 33
  • 6

1 Answers1

0

You can check if you have errors with the chrome developer tools. I think that your problem is that you are not using the correct jQuery script. Try to add this after the title tag:

<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>

Edit:

Ok after the title tag put only the link tags and style tags. Before the end of the body put the script tags in that order:

  1. <script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
  2. <script type="text/javascript" src="jquery-ui.js"></script>
  3. yako script

If you don't want to use cdn you can download jQuery from here: https://code.jquery.com/jquery-3.1.1.min.js and in the src attribute direct to this file.

Sagie
  • 996
  • 3
  • 12
  • 25
  • Yeah it say JQuery is undefined – RittenRA Feb 17 '17 at 21:39
  • it said the following is not defined in my .js file – RittenRA Feb 17 '17 at 21:43
  • factory( jQuery ); } }(function( $ ) { – RittenRA Feb 17 '17 at 21:44
  • jquery-ui.js:14 Uncaught ReferenceError: jQuery is not defined at jquery-ui.js:14 at jquery-ui.js:16 (anonymous) @ jquery-ui.js:14 (anonymous) @ jquery-ui.js:16 default2.html:162 HTMLCollection[3] default2.html:163 HTMLCollection[3] default2.html:186 Uncaught ReferenceError: $ is not defined at default2.html:186 (anonymous) @ default2.html:186 – RittenRA Feb 17 '17 at 21:45