How to preselect and disable specific checkboxes using js jquery

0 votes

I have checkboxes with randomly generated ids on every page view and want to preselect and disable some of them, so they can not get unchecked anymore. Is it possible?

With a simple script which looks after value="" I'm able to achieve the preselection but if I try to disable it at the same time, it disables all input fields on the page.

On closer inspection I found out that they have these attributes in common: <div id="cb-selection">and <input name="mycb">.

What would be your solution if we had this:

<form method="post" id="submit-this" class="" enctype="multipart/form-data">
    <div id="cb-selection">
        <div>
            <input type="checkbox" name="mycb" id="?" value="Check1">
            <label for="?"> Check1 </label>
        </div>
        <div>
            <input type="checkbox" name="mycb" id="?" value="Check2">
            <label for="?"> Check2 </label>
        </div>
        <div>
            <input type="checkbox" name="mycb" id="?" value="Check3">
            <label for="?"> Check3 </label>
        </div>
    </div>
</form>

I would appreciate any help.

Jul 26, 2022 in Web Development by gaurav
• 23,260 points
212 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Web Development

0 votes
1 answer

how to add erroricon and custom validation message using jquery?

By default, the error message is put ...READ MORE

answered Jun 30, 2022 in Web Development by rajatha
• 7,640 points
4,014 views
0 votes
1 answer

How to place images using jQuery masonry plugin to start

You were just missing a css class that adjusts ...READ MORE

answered Jun 22, 2022 in Web Development by rajatha
• 7,640 points
364 views
0 votes
1 answer

How to create a simple map using JavaScript/JQuery

var map = new Object(); // or ...READ MORE

answered Jun 27, 2022 in Web Development by rajatha
• 7,640 points
899 views
0 votes
1 answer

How to alert using jQuery

alert($('#test')); // or alert($('#test'). get(0)); // also try alert(document. ...READ MORE

answered Jun 27, 2022 in Web Development by rajatha
• 7,640 points
760 views
0 votes
1 answer

How to Fade In/Out multiple texts using CSS/jQuery like on Droplr?

The jQuery fadeIn() method is used to ...READ MORE

answered Jun 29, 2022 in Web Development by rajatha
• 7,640 points
1,017 views
0 votes
1 answer

How to change an element's title attribute using jQuery

You can change the title attribute with ...READ MORE

answered Jun 30, 2022 in Web Development by rajatha
• 7,640 points
3,634 views
0 votes
1 answer

What is jQuery?

Hey, jQuery is a fast and concise JavaScript ...READ MORE

answered Feb 14, 2020 in JQuery by kartik
• 37,510 points
991 views
0 votes
1 answer

Uncaught TypeError: Cannot read property 'msie' of undefined - jQuery tools

Hello, Use the following script tag in your ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
14,236 views
0 votes
1 answer

Uncaught Error: Bootstrap's JavaScript requires jQuery

Hello @kartik, You have provided wrong order for ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
22,432 views
0 votes
1 answer

How to make Bootstrap popover Appear/Disappear on hover instead of click?

Hello @kartik, Set the trigger option of the popover to hover instead ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,880 points
2,965 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP