Jump to content

Hyperlink post value from radio button and display on Javascript message box


ivane

Recommended Posts

I am new to here.

 

I would like to design a PHP page for simple education system.

 

The page consist of 2 <tables>:

 

1. one comprehension passage;

 

2. 5 questions of multiple choices (e.g. option A to option D).

 

For the table 1, it's just display static passage.

But, in table 2, I would like to design two columns, one for question and the multiple choices, another column for "check the solution" ( this part will further discuss below).

 

Column 1 for table 2, I can display question and multiple choices (radio button format) in one row.

 

Column 2 for table 2, I need to display "check for solution" in hyperlink format.

This part may need some Javascript to help.

I need to allow user click the hyperlink, next will pop up a message box or small windows box to display the user's selected value from radio button (multiple choices) and also display the actual answer retrieved from database and stored in array at PHP page.

 

Here's a simple example of what you could do using jQuery:

<script src="jquery.js"></script>
<script>
function checkAnswer(id) {
selected = $("input[name=answer_"+id+"]:checked").val();
$.get("checkanswer.php", {id: id}, function(data) { alert("Your answer: "+selected+"\n\nCorrect Answer: "+data); });
}
</script>
<input type="radio" name="answer_123" value="A" checked="checked">A</input>
<input type="radio" name="answer_123" value="B">B</input>
<input type="radio" name="answer_123" value="C">C</input>
<input type="radio" name="answer_123" value="D">D</input>
<a href="#" onclick="checkAnswer(123); return false;">Check Answer</a>

 

Just code getanswer.php to take $_GET['id'] and get its answer from the database, assuming each question has some kind of unique id.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.