• Home
  • Jobs
  • coursesAndChallenges
  • Teachers
  • For business
  • Blog
  • ES/EN

0

13
Views
Getting checkbox value with js and ajax

According to the checkbox information I received from the frontend, I will record to the database in the backend. I am stuck in the part where I wrote not working as expected, please help.

Frontend;

$.ajax({
  url: '{{ route('diffacts.manage.confirm.process ') }}?a=e&id=' + data.id,
  method: 'GET',
  data: {
    date_start: $('#date_start').val(),
    duration: $('#duration').val(),
    operation_type_id: $('#diffact_type_id').val(),
    description: $('#description').val(),
    // the if / else not working as expected
    if ($('#FaturaDurum').is(":checked")) {
      document.getElementById('FaturaDurum').value = "1"
    } else {
      document.getElementById('FaturaDurum').value = "0"
    }
    FaturaDurum: $('#FaturaDurum').val()
  }
})

Backend;

if($request->input('FaturaDurum') == "1") {
  $faturadurum = 'Faturalandirilmamis';
}
else {
  $faturadurum = 'Faturalandirilmis';
}
14 days ago ·

Santiago Trujillo

1 answers
Answer question

0

I think it's better to write the code like this:

someValue : $('#FaturaDurum').is(":checked")
14 days ago · Santiago Trujillo Report
Answer question
Remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Startups
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.