onchange this.form.submit() not working for web form

后端 未结 2 1865
悲哀的现实
悲哀的现实 2021-01-23 11:45

been working on this way too long...but can\'t seem to identify the problem. Already read dozens of articles on stackoverflow and elsewhere.

when I click and change the

相关标签:
2条回答
  • 2021-01-23 12:01

    Probably you have element or JS object called form or submit somewhere, conflicting with the real form.

    Most safe way is using document.getElementById:

    <select onchange="SubmitForm('orderbyfrm');">
    

    And the JavaScript:

    function SubmitForm(formId) {
        var oForm = document.getElementById(formId);
        if (oForm) {
            oForm.submit(); 
        }
        else {
            alert("DEBUG - could not find element " + formId);
        }
    }
    

    Further debugging with good old alert.. instead of the alert("DEBUG ... have this:

    var sDebugInfo = "found " + document.forms.length + " forms: \n";
    for (var i = 0; i < document.forms.length; i++) {
        var curForm = document.forms[i];
        sDebugInfo += "name: " + curForm.name + ", id: " + curForm.id;
        sDebugInfo += "\n";
    }
    alert(sDebugInfo);
    

    Depending on what you get, debug should continue.

    0 讨论(0)
  • 2021-01-23 12:04

    sorry guys! I found the problem. I had a broken div around this form

    <div id="orderby" class="orderby
    <form id="xxx" name="xxx" action="#" method="post" class="orderbyfrm">
    

    fixed:

    Really appreciate your help everyone!

    0 讨论(0)
提交回复
热议问题