简体   繁体   中英

How can I go for next question without click next button?

I have small php quiz script something like this:

<input type="radio" value="1" id='radio1_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'/>
<label class="radio"  for='radio1_<?php echo $result['id'];?>'><?php echo $result['answer1'];?> </label>
<br/>
<input type="radio" value="2" id='radio2_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>' onclick="next()"'/>
<label class="radio"  for='radio2_<?php echo $result['id'];?>' ><?php echo $result['answer2'];?></label>
<br/>
<input type="radio" value="3" id='radio3_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>' />
<label class="radio"  for='radio3_<?php echo $result['id'];?>'/><?php echo $result['answer3'];?></label>
<br/>
<input type="radio" value="4" id='radio4_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'/>
<label class="radio"  for='radio4_<?php echo $result['id'];?>'><?php echo $result['answer4'];?></label>
<br/>
<button id='next1' class='next' type='button'>Next</button>

My question is when I am click on answer1 or 2 or 3 or 4 it will go for next question without click next button

Assign a class answer to each of the answer

$('.answer').click(function(){
    next(); 
     //next() should contain logic to go to next question
     //this.attr('id') this.attr('name')  should provide you name/id    
     //of answer clicked and based on it you could decide whats the     
     //current and next question
});

Or you could have a hidden variable hidden on page which will keep track of next question and in next() function populate next question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM