javascript - Why is document.forms["myform"]["input"].value return undefined -
so here's me trying make html5 version of tone matrix program. here's problem, have user enter how long want song , make sure entered number, used
function initiate(){ var min = document.forms["initiator"]["min"].value; var sec = document.forms["initiator"]["sec"].value; // logic return false;}
to check see if stuff entered indeed number when try this, browser spits "uncaught typeerror: cannot read property 'min' of undefined" here's what's in dom.
<form onsubmit="return initiate()"> song (at most): <input type="number" name="min" id="min"> minutes , <input type="number" name="sec" id="sec"> seconds long.<br> <input type="submit" value="start" /> </form><br>
i have placed thing onto hosting service located here http://www.sfu.ca/~zla49/mmc/ ya :)
you don't have name
on form.
it should <form name="initiator" onsubmit="return initiator()">
what may more beneficial, if don't want name form pass form object parameter:
function initiate(form){ var min = form["min"].value; var sec = form["sec"].value; // logic return false; } <form onsubmit="return initiate(this)"> <!--... rest of code ...-->
Comments
Post a Comment