what is the condition to check value from input text with javascript
I make a quiz app with codeigniter. When i publishing question i need to
check the option value with answer value. so how i make this check with a
suitable condition.or what is the condition for checking all this option
value with answer value? Below i show my 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[" + i + "]"].value;
var opt1=document.forms["myForm1"]["opt1[" + i + "]"].value;
var opt2=document.forms["myForm1"]["opt2[" + i + "]"].value;
var opt3=document.forms["myForm1"]["opt3[" + i + "]"].value;
var ans1=document.forms["myForm1"]["ans[" + i + "]"].value;
if ((qus1==null || qus1=="")||(opt1==null || opt1=="")||(opt2==null ||
opt2=="")||(opt3==null || opt3=="")||(ans1==null || ans1==""))
{
alert("All field must be 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/>
Answer : <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 i am possible to check all the filed must fill up. But 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 i check that at least one option value must match with answer ? what
is the condition i need to use ?
No comments:
Post a Comment