skip to Main Content

i want to update the details of a product using a modal whereby the details will be populated in the inputs and the user can change where they wish.i have been able to get the value of some details like the but am unbale to get the value of the details which has a dropdown and the one with a radio button select.i am using jquery ajax to fetch the data from the table and autopopulate it in the form.i have tried various methods getting the value of the dropdown and the radio button but it doesnt work.how can i get the values.here is my ajax code.

 //   show editing modal
$('body').on('click','#editrentalhsedetails',function(){
        var rentalhsedetailsid=$(this).data('id');
        $.ajax({
           url:'{{ url("admin/activerental",'') }}' + '/' + rentalhsedetailsid + '/edit',
           method:'GET',
           processData: false,
           contentType: false,
           success:function(response)
           {
              console.log(response.editrentalhsedetail);
              if (response.status==404)
              {
                 alert(response.message);
              } 
              else if(response.status==200)
              {
                 $('#editrentalhsedetailsmodal').modal('toggle');

                     //am able to get these values very well
                 $('#rentalhouseid').val(response.editrentalhsedetail.id);
                 $('.edit_title').html('Edit details for Rental house');
                 $('#rental_name').val(response.editrentalhsedetail.rental_name);
                 $('#monthly_rent').val(response.editrentalhsedetail.monthly_rent);
                 $('#rental-details').val(response.editrentalhsedetail.rental_details);
                 $('#totalrooms').val(response.editrentalhsedetail.total_rooms);

                      //this one is a dropdown and it doesnt work
                 $(".rentalselectcat").select2();
                 $(".rentalselectcat").val(response.editrentalhsedetail.housecategory.rentalcat_title);

                           //this is the radio button it doesnt check the value i have gotten from the tablr
                 $(".waterbill:checked").val(response.editrentalhsedetail.waterbill);
                 $(".electricitybill:checked").val(response.editrentalhsedetail.electricitybill);


            
              }
           }
        })
    })

this is my html code for the dropdown

 <div class="form-group inputdetails col-sm-6">
    <label>Rental category<span class="text-danger inputrequired">*</span></label>
      <select name="rentalhousecategory" class="rentalselectcat form-control text-white bg-dark" required style="width:100%;"> 
        @foreach($allrentalcategories as $category)
           <option value="{{ $category->id }}">{{ $category->rentalcat_title }}</option>
         @endforeach  
      </select>
   </div>

this is the html code for he checkbox

<div class="row section-groups">
   <div class="form-group inputdetails col-sm-6" style="text-align: left">
       <label>Water Bill<span class="text-danger inputrequired">*</span></label>
         <div class="col-sm-10">
            <label class="radio-inline">
            <input type="radio" name="waterbill" checked id="inlineRadio1" class="waterbill">Tenant Pays the Bill 
            </label>
            <label class="radio-inline">
               <input type="radio" name="waterbill" checked id="inlineRadio2" class="waterbill"> Rent Inclusive
            </label>
          </div>
        </div>

    <div class="form-group inputdetails col-sm-6" style="text-align: left">
       <label>Electricity Bill<span class="text-danger inputrequired">*</span></label>
       <div class="col-sm-10">
          <label class="radio-inline">
            <input type="radio" name="electricitybill" class="electricitybill" id="inlineRadio1">Tenant Pays the Bill 
          </label>                                 
          <label class="radio-inline">
              <input type="radio" name="electricitybill" class="electricitybill" id="inlineRadio2"> Rent Inclusive
           </label>
         </div>
       </div>
     </div>

how can i fix this.

2

Answers


  1. Give it a try because I am not sure if this is right.

    $('#select_id').val('option_val').change();

    Login or Signup to reply.
  2. @foreach($fromUpdateController as $nData)
    <select name="rentalhousecategory" class="rentalselectcat form-control text-white bg-dark" required style="width:100%;">            
                @foreach($allrentalcategories as $category)
                <option <?php if($nData->category_id == $category->id){ echo 'selected'; } ?> name="category_id" class="form-control" value="{{ $category->id }}">{{ $category->rentalcat_title }}</option>                       
                @endforeach
    </select>
    
    <input type="radio" name="waterbill" id="inlineRadio2" class="waterbill" <?php if($nData->waterbill == $category->waterbill){ echo 'checked'; } ?>> Rent Inclusive
    
    @endforeach
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search