Can not check blank selection field while submitting form using PHP and Javascript -
i have 1 issue while submitting form can not check blank selection field.i explaining code below.
addcomplain.php:
<form name="billdata" id="billdata" enctype="multipart/form-data" method="post" onsubmit="javascript:return checkform();"> <div class="input-group bmargindiv1 col-md-12"> <span class="input-group-addon ndrftextwidth text-right" style="width:180px"> name :</span> <input type="text" name="u_name" id="name" class="form-control" placeholder="add name" onkeypress="clearfield('name');"> </div> <div class="input-group bmargindiv1 col-md-12"> <span class="input-group-addon ndrftextwidth text-right" style="width:180px">email :</span> <input type="email" name="u_email" id="emailid" class="form-control" placeholder="add email id" onkeypress="clearfield('emailid');"> </div> <div class="input-group bmargindiv1 col-md-12"> <span class="input-group-addon ndrftextwidth text-right" style="width:180px">type of complaint :</span> <select class="form-control" id="compleant" name="complaintype" onchange="javascript:checkcomfield();"> <option value="">select types of complaint</option> <option value="card">card related</option> <option value="claim">claim related</option> <option value="product">product related</option> <option value="premimum">premimum related</option> </select> </div> <input type="submit" class="btn btn-success" name="complainsubmit" id="addprofiledata" value="add"/> </form> <script> function checkform(){ var s=document.billdata; console.log('compalin',s.complaintype.value==''); if(s.u_name.value==''){ alert('please enter name'); s.u_name.focus(); s.u_name.style.bordercolor = "red"; return false; }else if(s.u_email.value==''){ alert('please enter email'); s.u_email.focus(); s.u_email.style.bordercolor = "red"; return false; }else if(! validateemail(s.u_email.value)){ alert('please enter valid email'); s.u_email.focus(); s.u_email.style.bordercolor = "red"; return false; }else if(s.complaintype.value==''){ alert('please select type of complain'); s.complaintype.focus(); s.complaintype.style.bordercolor = "red"; return false; }else{ } } </script>
here problem when have value in name , email field , no value select selection field, clicking on add button form submitting blank selection field can not check.here need check blank field before submit.please me.
i checked code. throwing errors in console. functions clearfield
, validateemail
not defined. commented out these functions , working fine.
here demo same.
you can add functions clearfield
, validateemail
, check afterwards code working or not.
in demo have added these functions , working fine.
Comments
Post a Comment