html - Meaning of JavaScript form validation code? -
i have explain how specific javascript code validates web form, stuck of features do, section of code. understand first line defines rest of section should run if field field1
of form exampleform
left empty, not know purpose rest of code serves. know msg
variable created earlier in document empty default value, , result
variable default value of true. can me out explaining each line does?
if (document.exampleform.field1.value=="") { msg+="you must enter name \n"; document.exampleform.name.focus(); document.getelementbyid('field1').style.color="red"; result = false; }
in plain english:
if document form field value equal empty string, set error message msg
, focus on element, , give red color user knows it's error, , set result false, whatever you're going use later in code/function.
Comments
Post a Comment