javascript - How to validate textarea and radio button in a loop -


i need 1 help. have multiple textarea, radio button , dropdown list created clicking on button. need validate them textarea has blank value, radio button check , dropdown select using javascript/jquery. explaining code below.

<div style="width:24%; float:left; padding:10px;">no of questions :  <input name="no_of_question" id="ques" class="form-control" placeholder="no of question" value="<?php if($_request['edit']) { echo $getcustomerobj->no_of_question; } else { echo $_request['no_of_question']; } ?>" type="text" onkeypress="return isnumberkey(event)"> </div> <div style="padding-bottom:10px;"> questions : <input type="button" class="btn btn-success btn-sm" name="plus" id="plus" value="+" onclick="addquestionfield();"><input type="button" class="btn btn-danger btn-sm" name="minus" id="minus" value="-" onclick="deletequestionfield();"> </div>  <script> function addquestionfield(){     var =$("#ques").val();     if(get==null || get==''){         alert('please add no of questions');     }else{         var counter = 0;         if (counter > 0){             return;         }else{              counter++;               <?php                    $status=array("status"=>'1');                    $feeddata=$db->kf_answertype->find($ustatus);              ?>             <?php                  $status=array("status"=>'1');                 $feeddatascale=$db->kf_scale->find($ustatus);             ?>              for(var i=1;i<get;i++){                    $('#container').append('<div><div style="width:24%; float:left; padding:10px;"> <textarea class="form-control" name="questions'+ +'" id="questions'+ +'" placeholder="questions"  style="background:#ffffff;"  rows="2"><?php if($_request['edit']) { echo $getcustomerobj->questions; } else { echo $_request['questions']; } ?></textarea></div><div style="float:left;margin-top:37px;"><div style="float:left; margin-right:10px;"><?php foreach($feeddata $v){?> <input type="radio" name="answer_type'+i+'" id="answer_type0" onclick="selectscale(this.value,'+i+');" value="<?php echo $v['_id']; ?>"> <?php echo $v['answertype']; ?> <?php }?></div><div style="float:left; margin-top:-10px;display:none;" id="scaleid'+i+'"><select class="form-control" id="nscale'+i+'" name="noofscale'+i+'"><option value="">select answer type</option><?php foreach($feeddatascale $v){ ?><option value="<?php echo $v['_id']; ?>" <?php if($getcustomerobj->no_of_scale == $v['_id'] or $_request['no_of_scale'] == $v['_id']){ print 'selected'; } ?>><?php echo $v['noofscale']; ?></option><?php } ?></select></div><div style="clear:both;"></div></div><div style="clear:both;"></div></div>');               }          }     } } </script> 

here when user click on + button multiple textarea, radio button , dropdown list dynamically. here need when form submit need check validation of whether not blank/checked. please me.

from can understand question, have deduced have form input controls. user can press '+' replicate/clone div containing input providing additional form filled input controls. if case, can use following validation ensure visible input controls have been filled data.

pre-requisite: ensure forms assigned same class name.

example:

var visibledivs = $(".displayablediv:visible"); // .displayablediv name of class containing form controls var hasvalue = true; // loop on visible divs for(i = 0; < visibledivs.length; ++i) {     $(visibledivs[i]).find('input')     .each(function() { // iterates on input fields found         if($.trim($(this).val()).length === 0) {             hasvalue = false; // if field found without value             break;         }     }); }  if(hasvalue === false) {     // handle validation logic here (prompt user complete input areas etc) } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -