html - Check to see if form fields are empty using javascript -
i have working function checks if of forms fields not blank. part of form, have hidden div appear if 1 of fields has answer of yes selected in drop down. when have drop down item selected yes, function check if 1 of fields left empty, , when drop down has answer of no, don't want function check values of hidden div items. can't seem figure out way accomplish this. have tried far. variable label2 contains value of drop down menu, yes/no.
function validateoverage() { var drive2 = document.forms["overage"]["drivers2"].value; var prodes2 = document.forms["overage"]["proddes2"].value; var sizes2 = document.forms["overage"]["size2"].value; var cases2 = document.forms["overage"]["cs2"].value; var bottle2 = document.forms["overage"]["btls2"].value; var initials2 = document.forms["overage"]["chkitls2"].value; var label2 = document.forms["overage"]["ontrucks"].value; var routenum2 = document.forms["overage"]["routenum"].value; var stopnum2 = document.forms["overage"]["stopnum"].value; var custnum2 = document.forms["overage"]["custnum"].value; if (drive2 == null || drive2 == "" || prodes2 == null || prodes2 == "" || sizes2 == null || sizes2 == "" || cases2 == null || cases2 == ""|| bottle2 == null || bottle2 == "" || initials2 == null || initials2 == "" || label2 == null || label2 == "") { alert("fill in fields overage form"); return false; } else if (label2 == "yes" || routenum2 == null || routenum2 == "" || stopnum2 == null || stopnum2 == "" || custnum2 == null || custnum2 == "") { alert("fille in fields overage form"); return false; }*/ else if (cases2 == "0" && bottle2 == "0") { alert("both cases , bottles values can not 0"); return false; } else { alert("data added overage form"); } }
html code have in body has hidden contents
<td style = "visibility: hidden"><input type = "number" id = "routenum"> </input></td> <td style = "visibility: hidden"><input type = "number" id = "stopnum"> </input></td> <td style = "visibility: hidden"><input type = "number" id = "custnum"> </input></td>
Comments
Post a Comment