I want to know how to get the array index values dynamically.
Here I am customizing the quizy-fillintheblanks.master.zip files used in my coding:
<script>
$('#tutorial-fillblank').quizyFillBlank({
textItems:['The first president of the United States of America is', '. The longest serving president of the country is ', '. He was succeeded by ', ', who led the country till the end of the Second World War. The first afro-american to be elected for this position is', '.'],
anItems:['John Kennedy', 'Franklin Roosevelt', 'George Washington', 'Ronald Reagan', 'Harry Truman', 'Richard Nixon', 'Barack Obama' ],
anItemsCorrect:[2,1,4,6],
blockSize:150
});
</script>
In above coding textItems are questions and anItems are answers, and anItemCorrect is the array index value for anItems.
In that coding I am customizing values I'm getting from a database into questions and answers. Here I don't know how to pass anItemCorrect value dynamically:
<script>
$('#tutorial-fillblank').quizyFillBlank({
textItems:[<?php foreach($question as $article) { echo "'".$article->question."',";}?>],
anItems:[<?php foreach($question as $article)
{$a[]=$article->answer;}
$arr=$a; shuffle($arr); foreach($arr as $ans => $val) {echo "'".$val."',";} ?> ],
anItemsCorrect:[<?php foreach($arr as $ans => $val) { echo "'".$ans."',";} ?>],
blockSize:150
});
</script>
How can I use jquery.inArray() to dynamically choose whether an answer is right or wrong?