Uncaught TypeError: forms.set is not a function



  • Help me, what's the chick? My eyes are licking, I want to sleep, I can't handle it.

    Uncaught TypeError: forms.submit is not a function

    <!DOCTYPE html>
    <html>
    <head>
     <title>Test</title>
    
    &lt;script&gt;
    

    var forms = {
    lockBtn: function(btn) {

    },

    set: function(type, hide) {
    switch(type) {
    case 1: {
    var forms = document.getElementsByClassName("form");

        for(var i = 0; i &lt; forms.length; i++) {
          forms[i].style.visibility = "hidden";
        }
    
        document.getElementById("form_first").style.visibility = ((hide) ? "hidden": "visible");
      }
    }
    

    },

    submit: function(type, btn) {
    switch(type) {
    case 1: {
    var number = document.getElementById("number").value;

        if(!number) {
          return document.getElementById("number").focus();
        }
    
        this.lockBtn(btn);
    
        var response = file_get_contents("", "POST", {
            act: "check_available",
            number: number
          },
    
          function(data) {
            alert(data);
          }
        );
      }
    }
    

    }
    }
    </script>
    </head>
    <body>
    <div class="form" id="form_first">
    <input type="text" id="number" placeholder="Введите номер...">

    <br> <br>

    <input type="submit" onmousedown="forms.submit(1, this);">
    </div>

    <script>
    window.onload = function() {forms.set(1, false);}
    </script>
    </body>
    </html>



  • forms returns the form collection, no method submit

    <form method='POST'></form>
    <form method='GET'></form>
    <button onclick='console.log(forms[0].method);'>Форма 1</button>
    <button onclick='console.log(forms[1].method);'>Форма 2</button>

    console.log(document.forms);
    <form method='POST'></form>
    <form method='GET'></form>


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2