Options are displayed in blue, and using JavaScript, I check if the background color is blue. If it's not, execute the next step; otherwise, display an alert message.
function click_option_A() {
var clr_1_chk = document.getElementById("1");
//alert(clr_1_chk.style.backgroundColor);
var clr_2_chk = document.getElementById("2");
var clr_3_chk = document.getElementById("3");
var clr_4_chk = document.getElementById("4");
if(clr_1_chk.style.backgroundColor !== "blue"){
alert("You have already selected this option!")
}
else if(clr_2_chk.style.backgroundColor !== "blue"){
alert("You have already selected this option!");
}
else if(clr_3_chk.style.backgroundColor !== "blue"){
alert("You have already selected this option!");
}
else if(clr_4_chk.style.backgroundColor !== "blue"){
alert("You have already selected this option!");
}
else{
var answer = "A";
var confirm = window.confirm("Are you sure?");
if (confirm) {
window.document.getElementById(answer).style.backgroundColor ="yellow";
var correct_answer = "B";
if(correct_answer == "A"){
//correct_ans();
setTimeout(correct_ans,3000);
}
else{
setTimeout(wrong_ans,3000);
}
}
}
}
// Repeat similar functions for options B, C, and D
function correct_ans(){
// Code for displaying correct answer
}
function wrong_ans(){
// Code for displaying wrong answer
}
td{
background-color: blue;
color: white;
}
<div class="container">
<table class="table table-bordered table-responsive">
<tr class="text-center">
<td colspan="2">Who was First Prime Minister of India?(15304)</td>
</tr>
<tr>
<td id="1" onclick="click_option_A()">A) M K Gandhi</td>
<td id="2" onclick="click_option_B()">B) Jawaharlal Nehru</td>
</tr>
<tr>
<td id="3" onclick="click_option_C()">C) Rajendra Prasad</td>
<td id="4" onclick="click_option_D()">D) Chandra Shekhar Azad</td>
</tr>
</table>
</div>
I attempted to use the provided code, but it consistently alerts me that I've made a selection even when I haven't.
The choices are styled in blue, and my script aims to validate the color before proceeding with the action. It will display an alert message if the color is not blue.