简体   繁体   中英

Javascript code not functioning correctly in Firefox or Chrome

I have been fighting with this for a couple of days now. I can't see why this wouldn't work in Chrome, but does work in IE.

The required drop-down box I want to appear doesn't, and it also does not write to the console screen. Any help would be great.

Thanks

    function showYear() {
        var typeReq = document.getElementById("Formtype");
        var aYear = document.getElementById("year");
        if (typeReq.value == "Upload") {
            console.log('upload selected');
            aYear.style.visibility ="visible";
        } else {
            console.log('View selected');
            loadUpload()
        }
    }

Internet Explorer's implementation of getElementById will return an element with the name attribute if it matches the parameter of the function. Make sure you use the id attribute in your HTML:

<!-- wrong -->
<input name="Formtype" />

<!-- right -->
<input id="FormType" />

if i understood your problem correctly, you must be calling the function showYear(); before the DOM ready.

try calling the function once the DOM is ready.

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