I want to change the view of one page depending on which checkbox is checked. Also when one is checked another becomes unchecked.
<input class="searchType" type="checkbox"></input>
<input class="searchType2" type="checkbox"></input>
I tried something like this but I don't know how to add another solution(if another checkbox is checked)
$('.searchType').click(function() {
    alert($(this).attr('id'));  //-->this will alert id of checked checkbox.
       if(this.checked){
            $.ajax({
                type: "GET",
                url: 'projects/index',
                data: $(this).attr('id'),
                success: function(data) {
                    alert('it worked');
                    alert(data);
                    $('#container').html(data);
                },
                 error: function() {
                    alert('it broke');
                },
                complete: function() {
                    alert('it completed');
                }
            });
            }
      });
      $('.searchType2').click(function() {
          alert($(this).attr('id'));  //-->this will alert id of checked checkbox.
          if(this.checked){
              $.ajax({
                  type: "GET",
                  url: 'projects/categories',
                  data: $(this).attr('id'), 
                  success: function(data) {
                      alert('it worked');
                      alert(data);
                      $('#container').html(data);
                  },
                  error: function() {
                      alert('it broke');
                  },
                  complete: function() {
                      alert('it completed');
                  }
              });
          }
      });
When I try code like this, in the server console I get for first checkbox:
Rendering projects/index.html.erb
Completed 200 OK in 217ms (Views: 197.8ms | ActiveRecord: 7.0ms)
And if other is checked
Rendering projects/categories.html.erb
Completed 200 OK in 217ms (Views: 197.8ms | ActiveRecord: 7.0ms)
It seems like it works but in reality, it does not change any route, all remains the same
Cheers
 
     
     
    