0

I have a checkbox that in case it's 'checked' it goes as true in the database, otherwise it's false. I want to this result appear with the checked checkbox if its true but it's not working.

CHECKBOX:

<span class="new-event-detail"><span><input type="checkbox" id="toCheck" class="addReedemButton" name="addReedemButton" value="true"/>Add Reedem Button</span></span>

GETTING DATA FROM DATABASE

let hasButton = promotions['add_button']

LOGIC:

if(hasButton == true){
    console.log('true', eventName)
    $("#toCheck").prop('checked',true)
    $("#toCheck").attr('checked','checked')
}else{
    console.log('false', eventName)
    $("#toCheck").prop('checked',false)
}

None of this seems to be working, because I'm getting the result that is true or false but the checkbox is never checked.

MCM
  • 141
  • 2
  • 15
  • 2
    What version of jQuery are you using? See https://stackoverflow.com/a/19630917/1302730 – DotNetDublin Mar 12 '19 at 17:01
  • Your question is unclear please add the working code and explain a little more – Maheer Ali Mar 12 '19 at 17:04
  • Are you trying to say true false is coming from database? Have you checked what is shown in console with console.log statement? – Ishpreet Mar 12 '19 at 17:12
  • Yeah with the console.log I'm getting the name of the div and if they're true or false. Also, I'm using jQuery 3.3.1 but the '.prop('checked', true)' it's not working :/ – MCM Mar 12 '19 at 18:00

0 Answers0