Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 622551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:59:48+00:00 2026-05-13T18:59:48+00:00

I am having trouble checking checkboxes via JQuery – I have done this: if(element[1]==3)

  • 0

I am having trouble checking checkboxes via JQuery – I have done this:

if(element[1]==3)
  alert('#'+element[0]+'_1');//shows #chk_1
  $('#'+element[0]+'_1').attr('checked', true);
  $('#'+element[0]+'_2').attr('checked', true);
  $('#'+element[0]+'_3').attr('checked', true);    
}

I know it gets to that point because I can see the alert window with the correct variable name. I have also included JQuery and my firebug isn’t complaining about any errors, its just nothing is happening.

I have a few other functions which are active on a user click:

onclick="checker($(this).attr('id'));" 

Which essentially checks if a user is allowed to tick the checkbox but this shouldn’t get activated if I use the above method, correct? Plus I have done the automated ticks in such a way that those rules are preserved and the user is allowed to tick the checkboxes.

I am able to click the checkboxes and those rule checks are done correctly in the checker function.

HELP! I have no idea what’s wrong to be frank.

I appreciate nay help.

Update

With Pekka’s advice I have found that no JQuery function seems to be working for example:

$('#'+element[0]+'_1').hide();

Did nothing. So it means the ID of the element has a problem? But the element does exist and its the correct name!

I have given the checkbox a value and tried this:

alert($('#'+element[0]+'_1').val());

I get “undefined” returned! Why?

Update 2

Testing if it has been checked:

$('#'+element[0]+'_1').attr('checked', true);

if ($('#'+element[0]+'_1'+':checked').val() !== null) {
   alert('#'+element[0]+'_1');
}

This showed me the alert box. So it seems it is checked but I can not see it?

Update – Solution

Don’t be a noob like me and wrap JQuery code with: $(document).ready(function() {

I managed to waste everyones time having not done this, I think that bit of code is going to become standard for me from now on.

Thank you everyone for the continued help! 🙂 I’ll have to give to the person [lillq] that mentioned document load!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:59:49+00:00Added an answer on May 13, 2026 at 6:59 pm

    One thought is:

    If you have more than one chk_1, chk_2, chk_3 ids in your html, the $('#'+element[0]+'_2').attr('checked', true); will only effect the first one in your document.

    I ran the code you supplied as such:

    html

    ...
    <body>
        <input type="checkbox" id="el1" onclick="checker($(this).attr('id'));" />Text<br />
        <input type="checkbox" id="el2" onclick="checker($(this).attr('id'));" />Text<br />
        <input type="checkbox" id="el3" onclick="checker($(this).attr('id'));" />Text<br />
    </body>
    </html>
    <script type="text/javascript">
        init();
    </script>
    

    javascript

    function init () {
        $('#el1').attr('checked', true); 
        $('#el2').attr('checked', true); 
        $('#el3').attr('checked', true); 
    }
    function checker(id)
    {
        alert(id);
    }
    

    The init function here checks all of the boxes after the document has loaded. Is there any other info that you could give us help out.

    I like to reduce examples like this to the simplest code that fails.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 344k
  • Answers 344k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Too over your head? Depends on what you hope to… May 14, 2026 at 5:43 am
  • Editorial Team
    Editorial Team added an answer You'd need OCR for that. Rolling your own OCR would… May 14, 2026 at 5:43 am
  • Editorial Team
    Editorial Team added an answer I found it! It's here: http://wiki.greasespot.net/Greasemonkey_Manual:Editing Greasemonkey has to edit… May 14, 2026 at 5:43 am

Related Questions

I am writing a web app in Grails with the Acegi/Spring Security plug-in, and
I have an In-house windows form app that I would like to use Spell
I've been investigating frame breaking code recently and have come across some really bizarre
I have a base class called Component. I also have 2 interfaces I2DComponent, and
(Using Visual Studio 2005 / .NET 2.0) I have a DataSet which is being

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.