0

I am trying to select for 2 attributes that are variable on a multiple choice quiz. I echoed the correct answer to each question in an input that doesn't display on the page. I think my line where I select for 2 different attributes is the problem.
JQUERY:

        var zz = 1;

        while (zz <= <?php echo $num_rows ?>){  //I'm 100% postive $num_rows returns a value of 3
        var zstring = '#answer' + zz;

        var theanswer = $(zstring).attr('value');  //should return "a" or "c" or whatever the answer is

        if $("input[name=zz][value=theanswer]").is(':checked') {  //this is the line that's not working

              alert("the code worked");
        }       

        zz++;       
        } 

HTML echoed from PHP

echo "<input type='radio' name=" . $question_number ." value='a'> A. " . $chA . "<br><br>";
echo "<input type='radio' name=" . $question_number ." value='b'> B. " . $chB . "<br><br>";
echo "<input type='radio' name=" . $question_number ." value='c'> C. " . $chC . "<br><br>";
echo "<input type='radio' name=" . $question_number ." value='d'> D. " . $chD . "<br><br>";
echo "<input type='radio' name=" . $question_number ." value='e'> E. " . $chE . "<br>";
echo "<input type='text' id='answer".$question_number."' style='display: none;' value='".$correct."' />";

1 Answer 1

2

I see that in the if statement you have this:

if $("input[name=zz][value=theanswer]").is(':checked') {  //this is the line 

it should be:

if ($('input[name="zz"][value="theanswer"]').is(':checked')) {  //this is the line 
Sign up to request clarification or add additional context in comments.

1 Comment

I misunderstood the question, here is a fiddle with your answer jsfiddle.net/h5s7bn1v/4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.