Kanchan186
2 months ago

Uncaught TypeError: Cannot read property 'querySelector' of null

Posted 2 months ago by Kanchan186

view

<form class="m-t-40" method="post" action="{{url('/')}}/mechanic_brands/{{$mechanic->mechanic_id}}" enctype="multipart/form-data">
                                    {{csrf_field()}}

                                
                                      <div class="form-group">
                                        <h5>Segment<span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                @foreach($segment as $sg)
                                <ul><li>
                               <input type="checkbox" value="{{$sg->segment_id }}" name="sg[{{$sg->segment_id }}]" id="{{$sg->segment_id }}" onclick="getBrand1(this.id)" class="test">

                                <label  for="{{ $sg->segment_id }}">
                                <p>{{$sg->segment_name }}</p></label></li></ul>
                                
                                @endforeach
                                        </div>

                                       
                                    </div> 

                    <div class="form-group">
                         <div class="controls">
                             <table id="brands">
                                <tr><td> 
                                    <tbody>           
                                    <input type="checkbox"  name="brand_id"></td></tr>
                                    </tbody>
                                    </table>
                            </div>
                         </div>

                         
                                    

         
                                               
                                            <div class="text-xs-right">
                                                <button type="submit" class="btn btn-info">Submit</button>
                                                <button type="reset" class="btn btn-inverse">Cancel</button>
                                            </div>
                                </form>

controller

public function brandAjax($segment)
    {
      
        $brand=brands::where("segment_id",$segment)
                ->pluck('brand_name','brand_id')->all();
        return json_encode($brand);
    }

script

<script type="text/javascript">

       function getBrand1(id)
   {
          //  alert('Choose brands!');

 if(document.getElementById(id).checked)  
   {  
       
       $.ajax({
        url: 'http://localhost/partsanalysis/public/brand/Ajax/'+id,
       type: "GET",
       dataType: "json",
        error: function(data, errorThrown)
          {
              console.log('request failed :'+errorThrown);
          },
       success:function(result) {
         console.log(result);
        // alert(result);


                 /*       $.each(result, function(index, value) { 
                        //alert(value); 
                        // $("#brands").html('<input type="checkbox" />'+value ); 
                        var markup = "<tr><td><input type='checkbox' name='brand_id'></td><td>" + value + "</td></tr>";
                        $("#brands").append(markup);


                      }); */

                       $.each(result, function(index, value) { 
                        //alert(value); 
                        // $("#brands").html('<input type="checkbox" />'+value.brand_name ); 
                        var markup = "<tr><td><input type='checkbox' name='brand_id'></td><td>" + value.brand_name + "</td></tr>";
                        $("#brands").append(markup);

                      });



                   }
              });
          }     
      
        else
            {
                $("#brands").html(""); 
            }
        

        }

</script>

Please sign in or create an account to participate in this conversation.