简体   繁体   中英

Uncaught Typeerror, Broken JS

I have a menu drop down and a series of filter drop downs, both of which have been working fine up until today.

After adding a logo, with css, to the menu drop down, when I select a filter it breaks my javascript for the menu and the menu doesn't work at all. I get an Uncaught Typeerror.

The filters use forms and 'get' to sort with the onChange set to re-submit the page with the appropriate 'get' parameters.

Here is the menu html

<button id="burg" onclick="menuChange();" class="hamburger">&#9776;</button>
<button id="xCross" onclick="menuChange();" class="cross">&#735; </button>
<ul id="navList">
            <div class="nav-item">
                <a href="inventory.php">
                    <li>Inventory</li>
                </a>
            </div>
            <div class="nav-item">
                <a href="#">
                    <li>Finance</li>
                </a>
            </div>
            <div class="nav-item">
                <a href="contact.php">
                    <li>Contact Us</li>
                </a>
            </div>
            <div class="nav-item">
                <a href="about.html">
                    <li>About Us</li>
                </a>
            </div>
            <div id="lastNav" class="nav-item">
                <a href="reviews.html">
                    <li>Reviews</li>
                </a>
            </div>

            <div class="" id="navImage">
                <a href="index.html">
                    <li><img src="images/asmOriginalLogo_V4.png" alt="Arizona Specialty Motors"/>
                        <div id="dropDownSocial"> <a href="#"><img class="socialMediaLinks" src="images/fbLogo.png" alt="Facebook"/></a> <a href="#"><img class="socialMediaLinks" src="images/In-Black-128px-TM.png" alt="LinkedIn"/></a> <a href="#"><img class="socialMediaLinks" src="images/instaGlyph.png" alt="Instagram"/></a> <a href="#"><img class="socialMediaLinks" src="images/twitterLogo.png" alt="Twitter" /></a> </div>
                    </li>
                </a>
            </div>
        </ul>
<div id="dropdownFreeze">

Here is my javascript function to open/close the menu.

function menuChange() {
"use strict";
/****** Variables *****/


// Burger link & image
var burger = document.getElementById("burg");
// Individual drop down elements; home, inventory, etc.
var lines = document.getElementsByClassName("nav-item");
// Overall container; to make dropdown 'un-scrollable'
var mainArea = document.getElementById("dropdownFreeze");
// Cross link & image
var cross = document.getElementById("xCross");
// Background for dropdown & navigation
var navList = document.getElementById("navList");
// Social Media images & buttons
var social = document.getElementById("navImage");


// If menu is open, close it. If closed, open it
if (burger.style.display === 'none') {
    burger.style.display = 'block';
    cross.style.display = 'none';

    navList.style.display = 'none';
    social.style.display = 'none';

    for (var i = 0; i < lines.length; i++) {
        lines[i].style.display = 'none';
    }

    mainArea.style.position = 'relative';


} else {

    burger.style.display = 'none';
    cross.style.display = 'block';

    navList.style.display = 'block';
    social.style.display = 'block';

    for (var j = 0; j < lines.length; j++) {
        lines[j].style.display = 'block';
    }


    mainArea.style.position = 'fixed';


}



}

Here is one of my filters (all of them cause issues now, but didn't before adding the 'navImage' div)

<form name="sortMake" action="inventorySort.php?limit=10&page=1" method="get">
<select name="makeOrder" class="dropButton" onchange=this.form.submit();>
<option value="choose">Make</option>
<?php

$makeQuery = "select distinct make from vehicle order by make asc";
$makeResult = mysqli_query( $con, $makeQuery );
$selectMakeCount = 0;
if ( $makeResult ) {
    while ( $makeRow = mysqli_fetch_array( $makeResult ) ) {


        if ( isset( $_GET[ 'makeOrder' ] ) && $_GET[ 'makeOrder' ] == $makeRow[ 'make' ] ) {
            echo '<option value="' . $makeRow[ 'make' ] . '"selected>' . $makeRow[ 'make' ] . '</option>';

        } else {

            echo '<option value="' . $makeRow[ 'make' ] . '">' . $makeRow[ 'make' ] . '</option>';
                }

            }
        }


?>
</select>

The Uncaught Typeerror points to

mainArea.style.position = 'relative';

And to

navList.style.display = 'block';

It says that it cannot read property 'style' of null.

I'm fairly certain the issue is happening in the filter/get.

Wow I feel like a scrub.

For whatever reason, my ids for navList and dropDownFreeze got deleted from one of my pages. After resetting them, it worked perfectly.

Code: 1 Me: 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM