Why is document.forms[“myform”][“input”].value return undefined-Collection of common programming errors

So here’s me trying to make a HTML5 version of the Tone Matrix program. So here’s the problem, I have the user enter how long they want their song to be and then to make sure they entered a number, so i used

  function initiate(){
  var min = document.forms["initiator"]["min"].value;
  var sec = document.forms["initiator"]["sec"].value;
  // some logic
  return false;}

to check to see if the stuff they entered is indeed a number but when I try to do this, the browser spits back “Uncaught TypeError: Cannot read property ‘min’ of undefined” here’s what’s in my DOM.


Your song will be (at most):  minutes and  seconds long.

i have also placed the thing onto a hosting service located here http://www.sfu.ca/~zla49/MMC/ so ya Thanks 🙂

  1. You don’t have a name on your form.

    It should look like

    What may be more beneficial, if you don’t want to name the form is to pass the form object as a parameter:

    function initiate(form){
      var min = form["min"].value;
      var sec = form["sec"].value;
      // some logic
      return false;
    }
    
    
    
    

Originally posted 2013-11-13 09:49:57.