Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 views
in Technique[技术] by (71.8m points)

javascript - Uncaught TypeError: Cannot set property 'onchange' of undefined at HTMLDocument on the function

in the console showing an error message on function that jquery.min.js:2 Uncaught TypeError: Cannot set property 'onchange' of undefined at HTMLDocument.

$(document).ready(function() {
    function change() {

        var form = this.form,
            Name_of_comp = form.elements.Name_of_comp,
            crr = $('.p1').hide(),
            icss = $('.p2').hide();


        if (Name_of_comp.value == 'Capacitor') {
            crr.show();

        } else
        if (Name_of_comp.value == 'Resistors') {

            crr.show();
        } else {
            icss.show();
            Name.value = ' ';
        }

    }

    var form = document.getElementById('add_name');
    form.elements.Name_of_comp.onchange = change;
    form.elements.Name_of_comp.onchange();
})
>     front end  
<td><select class="form-control" onchange="change()" id="dropdown1" name="Name_of_comp[]">
                                    <option value="">Select</option>
                                    <option value="Capacitor">Capacitor</option>
                                    <option value="Resistors">Resistors</option>
                                    <option value="IC">IC's</option></select>
question from:https://stackoverflow.com/questions/65840338/uncaught-typeerror-cannot-set-property-onchange-of-undefined-at-htmldocument

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...