php - what is the condition to check value from input text with javascript -


i make quiz app codeigniter. when publishing question need check option value answer value. how make check suitable condition.or condition checking option value answer value? below show view

<?php include_once('header.php'); ?> <?php include_once('tnavbar.php'); ?>  <script src="<?php echo base_url();?>/js/jquery-1.9.1.min.js"></script> <script type="text/javascript">   function validateform1(){ var j=3; //alert(j); for(var i=1; i<= j ; i++){ var qus1=document.forms["myform1"]["ques[" + + "]"].value; var opt1=document.forms["myform1"]["opt1[" + + "]"].value; var opt2=document.forms["myform1"]["opt2[" + + "]"].value; var opt3=document.forms["myform1"]["opt3[" + + "]"].value; var ans1=document.forms["myform1"]["ans[" + + "]"].value;  if ((qus1==null || qus1=="")||(opt1==null || opt1=="")||(opt2==null || opt2=="")||(opt3==null || opt3=="")||(ans1==null || ans1=="")) {   alert("all field must fill"); return false;   }  } for(var z=1; z<= j ; z++){ //var qus2=document.forms["myform1"]["ques[" + z + "]"].value; var opt4=document.forms["myform1"]["opt1[" + z + "]"].value; var opt5=document.forms["myform1"]["opt2[" + z + "]"].value; var opt6=document.forms["myform1"]["opt3[" + z + "]"].value; var ans2=document.forms["myform1"]["ans[" + z + "]"].value;  if ((opt4||opt5||opt6)==ans2)   {   //alert("answer not match"); return true;   }   else{   alert("answer not match");   return false;   }  //return true; } } </script>  <div class="maincontent_area"> <div class="container">     <div class="row">         <div class="span12">         <form id="myform1" action="<? echo base_url()."/index.php/tmcq_test/insertmcq";?>" onsubmit="return validateform1();" method="post">             <?php         for($i=1; $i<= 3; $i++){ ?>    question : <input type="text" name="ques[<?php echo $i;?>]"><br/>    option 1 : <input type="text" name="opt1[<?php echo $i;?>]" ><br/>    option 2 : <input type="text" name="opt2[<?php echo $i;?>]" ><br/>    option 3 : <input type="text" name="opt3[<?php echo $i;?>]" ><br/>    &nbsp;answer : &nbsp;<input type="text" name="ans[<?php echo $i;?>]" ><br/>     <br/>    <?php  //echo $value->answer;      } ?>                      <input type="hidden" name="quiz_name"  value="<?php echo $name;?>">                     <input type="hidden" name="sub_id"  value="<?php echo $sub_id;?>">                     <input type="hidden" name="quiz_number"  value="<?php echo $number;?>">                     <input type="hidden" name="time_number"  value="<?php echo $time_number;?>">          <input type="submit" name="submit" id="submit" value="create"  class="btn btn-info">           </form>         <a href="<? echo base_url()."/index.php/tmcq_test";?>"> <button class="btn btn-info"> exit  </button> </a>          </div>     </div> </div> 

<?php include_once('footer.php'); ?> 

here possible check filed must fill up. in second condition in

    for(var z=1;z<=j;z++) //var qus2=document.forms["myform1"]["ques[" + z + "]"].value; var opt4=document.forms["myform1"]["opt1[" + z + "]"].value; var opt5=document.forms["myform1"]["opt2[" + z + "]"].value; var opt6=document.forms["myform1"]["opt3[" + z + "]"].value; var ans2=document.forms["myform1"]["ans[" + z + "]"].value;  if ((opt4||opt5||opt6)==ans2)   {   //alert("answer not match"); return true;   }   else{   alert("answer not match");   return false;   }  //return true; } } 

how check @ least 1 option value must match answer ? condition need use ?

you have comparison individually:

if (opt4 == ans2 || opt5 == ans2 || opt6 == ans2){     console.log("answer matches");     return true; }else{     console.log("answer not match");     return false; } 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -