An error is issued:

Cannot set property 'onsubmit' of undefined **

How to document.regform determine? There is a form in html named regform

 document.regform.onsubmit=function(){ var error=document.getElementById('error'); if(document.regform.name.value == ""){ error.style.display='block'; error.innerHTML="Вы забыли ввести имя"; document.regform.name.focus(); return false; } if(document.regform.sername.value == ""){ error.style.display='block'; error.innerHTML="Вы забыли ввести Фамилию";document.regform.sername.focus();return false; } if(document.regform.pass.value == ""){ error.style.display='block'; error.innerHTML="Вы забыли ввести пароль";document.regform.password.focus();return false; } if (document.regform.pass.value.length<6) { error.style.display='block'; error.innerHTML="Пароль должен быть от 6 до 20 символов";document.regform.password.focus();return false; }if (document.regform.pass.value.length>20) { error.style.display='block'; error.innerHTML="Пароль должен быть от 6 до 20 символов";document.regform.password.focus();return false; } if(document.regform.email.value == ""){ error.style.display='block'; error.innerHTML="Вы забыли ввести Email";document.regform.email.focus();return false; } return true; } 
  • Plus Alex, at least in translate.google.com error translated - makregistr
  • Does this error appear in all browsers (FireFox / Opera / MSIE / etc ..)? - chernomyrdin
  • Yes, the error in all browsers - JustK

3 answers 3

Most likely you have an onsubmit adding in head script , and a form in body , therefore you need to do so that the onsubmit prescription happens after the DOM is fully built or the script is below the form tag, for example:

 <form name="regform"> ... </form> <script type="text/javascript"> document.regform.onsubmit = ... </script> 

To control DOM loading, you can either use jQuery, or in a proven way:

 <head> ... <script type="text/javascript"> function init() { document.regform.onsubmit = ... } </script> ... </head> <body onload="init"> 
  • Thank you bro) It helped) - JustK
  • So I do not understand - what was the reason for jQuery here? - Zowie
  • To control DOM loading, you can use jQuery: <head> ... <script type = "text / javascript" src = "jquery.js"> </ script> <script type = "text / javascript"> $ (document) .ready (function () {document.regform.onsubmit = ...}); </ script> ... </ head> <body> ... <form name = "regform"> ... </ form> ... </ body> - chernomyrdin
  • To control the loading of the DOM, you can use almost any javascript framework, for example, dojo, prototype, ext, etc. And this is understandable by definition, I just really don’t understand why there was mentioning JQuery ... Then you’ll see examples for all popular frameworks, but it looks as if such “great” things are under the sole “great” jquery;) you are simply written - either as a jQuery, as if - there are no alternatives - Zowie
  • The phrase sounds like / use jQuery or ... / then that this can be done on any other convenient framework, there is not any doubt, just like all the examples I have given in the answer do not use jq - chernomyrdin

"May" because:

  document.regform === undefined 
  • How to document.regform do not undefined? - JustK
  • In html, add the name="regform" attribute to the form, or use the option suggested by @ling. I can assume that you have a name registered for the form and you just execute your javascript code not on the onload event. , ie: onload = function () {// and your code is already here ...} - Zowie

Set the form id = "regform" , and then select it through var form = document.getElementById("regform"); .