html - Form onsubmit issue with javascript -
ok confused on whole javascript in html stuff. trying validate form either "onblur" or on submit external file.
here html code works first field:
<script> function notempty(rep, errmsg) { var errmsg = "please enter in rep"; var rep = document.getelementbyid('submitted_by_hrrep'); if(rep.value == '') { alert(errmsg); hrrep.focus(); return false; } return true; } </script>
this in body of form near field.
<script type="text/javascript">document.getelementbyid("submitted_by_rep").onblur=notempty;</script>
so work , pop alert tells em go can't work doing rest (15 fields) of form. "onsubmit" confusing me , think it's right not sure.
<form onsubmit="return formvalidation()" method="post" action="process.asp" >
anything help
edit
function validate() { if(document.newemprequest.submitted_by_hrrep.value ==='') { alert("please provide name"); document.newemprequest.submitted_by_hrrep.focus(); return false; }
i got frustrated started scratch , took field @ time. found works fields need text, looks messy file calling externally works flawlessly.
i wish use jquery seems more complex setup need. :)
you have grab inputs iterate on them loop of flavor, maybe loop?
with jquery it's easy since there form validator plugins out there, , selectors friendly. using jquery,
$('#formid input')
would grab inputs in form, can use .each() iterate through inputs
you aren't going able .focus() on of fields though, need function handle entire list instead of one.
Comments
Post a Comment