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

  • SEARCH
  • Home
  • 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 7689659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:12:55+00:00 2026-05-31T20:12:55+00:00

I have the next code: js: $(‘[id^=check-]’).change(function(){ var new_id = this.id.replace(/check/, ‘new’), real_id =

  • 0

I have the next code:

js:

    $('[id^="check-"]').change(function(){
        var new_id = this.id.replace(/check/, 'new'),
            real_id = this.id.replace(/check/, 'real');
        if ($(this).is(':checked')) {
            $('#'+real_id).val($('#'+new_id).text());
        } else {
            $('#'+real_id).val(0);
        }
    });

html:

<tr>
  <td><span id="new-1">2</span></td>
  <td><input type="text" name="real-1" id="real-1" value="0"></td>
  <td><input type="checkbox" class="card" id="check-1"></td>
</tr>
<tr>
  <td><span id="new-2">7</span></td>
  <td><input type="text" name="real-2" id="real-2" value="0"></td>
  <td><input type="checkbox" class="card" id="check-2"></td>
</tr>
<tr>
  <td><span id="new-3">4</span></td>
  <td><input type="text" name="real-3" id="real-3" value="0"></td>
  <td><input type="checkbox" class="card" id="check-3"></td>
</tr>

The main idea: take the text from new-* and put it into real-* inbox when you click on related check-* checkbox.

Now I want to add another checkbox that mass executes this operation for all the elements.
I tried it:

    $('#main-checkbox').change(function(){
        if ($(this).is(':checked')) {
            $('.card').attr('checked', true);
        } else {
            $('.card').attr('checked', false);
        }

    });

But it does not work. Why?
How can I start the change action for all those checkouts.

Thanks.

  • 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-31T20:12:57+00:00Added an answer on May 31, 2026 at 8:12 pm

    Changing field values (including checked status) via JavaScript doesn’t trigger change events, but you can call the .change() method explicitly. Your function can also be simplified – you don’t really need the if/else structure:

    $('#main-checkbox').change(function(){
        $('.card').attr('checked', this.checked).change();
    });
    

    Demo: http://jsfiddle.net/4qs4d/

    Note that $(this).is(':checked') is just a slow way of saying this.checked. Also, if you are using jQuery 1.6 or later you should use the .prop() method rather than .attr().

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

Sidebar

Related Questions

I have problem with ajax and php.I have next code $(form).submit(function() { var poruka
I have next code: var ordinaryPropertyValue = new Catalog.Core.Entities.OrdinaryPropertyValue(); Environment.CurrentDirectory = System.IO.Path.GetTempPath(); var fileFile
I have the next code var uv:URLVariables = new URLVariables(); //lot of them in
I have the next function: function setImagesWidth(id,width) { var images = document.getElementById(id).getElementsByTagName(img); for(var i
I have next code block: $.post('page.php', function(data) { //data - full page info });
I have next code in my website. This code is an c# activex, the
I have the next code: dom.remove_class = function(element, class_name) { // For Chrome, Firefox...
I have the next code: $(document).ready(function () { $('#imgone').hide().delay(500).fadeIn(1000).delay(4500).fadeOut(500); $('#imgtwo').hide().delay(1500).fadeIn(1000).delay(3500).fadeOut(500); $('#imgthree').hide().delay(2500).fadeIn(1000).delay(2500).fadeOut(500); }); It's more
I have next JS code where I call controller method SaveSettings: function SaveSettings() {
i have next php code <?php class A { public function foo() { }

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.