0

I am trying to skip questionnaire automatically to see my exam marks easily. Because I don't want to do this manually for each exam. So I am writing a script to do that.
    setTimeout(function(){
    $(".btn-danger:eq(0)").click();
    setTimeout(function(){
        
         $(".multiselect:eq(0)").click().first();
         setTimeout(function(){   
             $('.checkbox input[type=checkbox]').prop('checked', true).click();
         }, 2000);
         setTimeout(function(){
             $(".multiselect:eq(1)").click().next();
             $('.checkbox input[type=checkbox]').prop('checked', true).click();
         }, 2000);
         setTimeout(function(){
             $(".multiselect:eq(2)").click().next();
             $('.checkbox input[type=checkbox]').prop('checked', true).click();
         }, 2000);
       }, 5000);
     });

There is many radiobuttons, textboxes and multiple dropdown list with checkbox. Everything is ok except the multiple dropdownlist with checkboxes.
This code selecting all of the options like this:
[dropdownlist][1]

[1]: https://i.stack.imgur.com/SuCXk.jpg
There is 2 more dropdownlist here. Code select all of the options in order. When the first one ok, then the second one runs. But the first one's values getting unselected. When the third one runs the second one getting unselected too. Only the last one works correctly.

How can I achive my goal?

abka
  • 1
  • 2
  • 1
    `setTimeout()` is not blocking. The callbacks of the "inner" `setTimeout(..., 2000)` calls are all executed at the same time. – Andreas Dec 12 '20 at 15:54
  • @Andreas it works fine. The code select the items in order. But then they being unselected. I tried first `setTimeout(..., 1000)` the second 2000, third 3000. When I clear the timeouts they not working orderly. only the last one works. The others do nothing. How can I do it seperately in one time. – abka Dec 12 '20 at 16:06
  • [link](https://stackoverflow.com/questions/5563783/jquery-class-click-multiple-elements-click-event-once/5563947) I have the same problem with this. But I couldn't work the solution. – abka Dec 12 '20 at 16:13

1 Answers1

0

There is my solution. This is about working of the click event in javascript. If we want to trigger it twice we need to put in a loop like this:

//getting the element with the classname.(classname is important)
var list = document.getElementsByClassName("input-small form-control");

setTimeout(function(){
    $(".btn-danger:eq(0)").click();
    setTimeout(function(){
        $('.panel-body input[type=radio]:nth-child(0)').prop('checked', true);
        for (var i = 0; i < list.length; i++) {
            list[i].setAttribute("value", "skip");
        }
        $('.checkbox input[type=checkbox]').each(function () {
                $(this).prop('selected', true).attr('checked', 'checked').click();
                $("li").addClass("active"); 
            });
   }, 2000);
   setTimeout(function(){
       $(".panel-footer > a").click();
   }, 7500);    
}, 5000);
abka
  • 1
  • 2