![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
function validate(evt){ evt = (evt) ? evt : ((event) ? event : null); if(evt){ var elem = (event.target) ? event.target : ((event.srcElement) ? event.srcElement : null); if(elem){ if(isNotEmpty(elem.name)){ if(isName(elem.name)){ if(isNotEmpty(elem.password)){ if(len16(elem.password)){ if(isNotEmpty(elem.email)){ if(validEmail(elem.email)){ return true; } } } } } } } } return false; } |
#2
| |||
| |||
|
|
kevinmaj... (AT) gmail (DOT) com wrote: function validate(evt){ evt = (evt) ? evt : ((event) ? event : null); if(evt){ var elem = (event.target) ? event.target : ((event.srcElement) ? event.srcElement : null); if(elem){ if(isNotEmpty(elem.name)){ if(isName(elem.name)){ if(isNotEmpty(elem.password)){ if(len16(elem.password)){ if(isNotEmpty(elem.email)){ if(validEmail(elem.email)){ return true; } } } } } } } } return false; } [snip] Your main problem I would surmise is with the validate function. When you submit your form, although you have assigned an event handler to it via javascript, there is no 'evt' being passed to your function. Nor will it ever. Since you don't want to actually hard code the event handler on your form, then you can do the following instead with your function: function validate() { var myForm = document.forms["inputform"]; if(myForm) { if(isNotEmpty(myForm.elements["name"])) { //etc. etc. } } } You can also get rid of all your id's in your form and just assign the name attribute. |
#3
| |||
| |||
|
|
kevinmaj... (AT) gmail (DOT) com wrote: function validate(evt){ evt = (evt) ? evt : ((event) ? event : null); if(evt){ var elem = (event.target) ? event.target : ((event.srcElement) ? event.srcElement : null); if(elem){ if(isNotEmpty(elem.name)){ if(isName(elem.name)){ if(isNotEmpty(elem.password)){ if(len16(elem.password)){ if(isNotEmpty(elem.email)){ if(validEmail(elem.email)){ return true; } } } } } } } } return false; } [snip] Your main problem I would surmise is with the validate function. When you submit your form, although you have assigned an event handler to it via javascript, there is no 'evt' being passed to your function. Nor will it ever. Since you don't want to actually hard code the event handler on your form, then you can do the following instead with your function: function validate() { var myForm = document.forms["inputform"]; if(myForm) { if(isNotEmpty(myForm.elements["name"])) { //etc. etc. } } } You can also get rid of all your id's in your form and just assign the name attribute. |
? And, more to
#4
| |||
| |||
|
#5
| ||||
| ||||
|
|
if(elem){ if(isNotEmpty(elem.username)){ if(isName(elem.username)){ if(isNotEmpty(elem.password)){ if(len16(elem.password)){ if(isNotEmpty(elem.email)){ if(validEmail(elem.email)){ return true; } } } } } } } } else { return false; } } |
|
function isNotEmpty(elem){ str = elem.value; re = /.+/; if(!str.match(re)){ return false; alert(elem.id + " is empty!"); |
|
} else{ return true; } |
|
} function isName(elem){ str = elem.value; re = /[a-zA-Z]*([ a-zA-Z]+\-?)*/; |
![]() |
| Thread Tools | |
| Display Modes | |
| |