Skip to content
Advertisement

how to get checkboxes values by name and check if these value exists in another array, become checked jquery laravel?

I’m trying to get values from checkboxes by their name, and check if these values exists in another array, if exists, so the values that exists, become (checked) by press a button, I use jquery for that, and tried a lot of ways but all checkboxes stills unchecked although I passed their values in if statement.

Checkboxes:

JavaScript

script(jquery):

JavaScript

it’s supposed the inputs which have values(1,2,3) become (checked) but all still (unchecked). any help please?

Advertisement

Answer

JQuery is outdated and not recommended anymore nowadays, var is also not recommended anymore, below I made a solution in pure JS:

JavaScript
JavaScript

Learn Modern JS at:

I know programming: https://exploringjs.com/impatient-js/

I don’t know programming: https://javascript.info/

All-in-one: https://phoenix35.js.org/

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement