Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
Can I make different buttons based on json boolean value?

Recently I asked about a dropdown with dynamic options based on the boolean value of a json property, and I got help and I absolute appreciate that. Over the course of that discussion I had a different idea to test but I'm having trouble implementing it.

an example of the users in the json file is

{"id":"2",
"username":"david",
"password":"1234",
"user_id":"127",
"date":"2022-02-14 23:45:37",
"is_admin":"1"}

the current javascript that loads a static table is

let data = JSON.parse(this.responseText);
    
    for(let i = 0; i < data.length; i++) {

    let row = `
     <tr>
<td>${data[i].username}</td>
<td>${data[i].password}</td>
<td>${data[i].user_id}</td>
<td>${data[i].is_admin == 1 ? "Yes" : "No"}</td>
     </tr>
    `;

    table.innerHTML += row;
}

It works, it makes the table and everything is good but in that last td I basically an trying

if(is_admin == true) {

make remove admin button
 
}else if (is_admin == false) {

make make admin button

}

but I'm struggling with how to do this. I've tried creating the button and appending it to the td but I get an error saying td is null, which I also don't understand. Do I need to do something different to append things to elements that were dynamically created?

I'm mostly just looking for a point in the right direction to try to work through this on my own. All of this is in vanilla javascript, if it matters. I have no experience using any frameworks yet.

Can I make a somewhat dynamic yes/no dropdown based on JSON file data? is a link to my previous question if there's any relevant information contained in it. Thank you very much.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!