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 6238643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:15:04+00:00 2026-05-24T11:15:04+00:00

$(document).ready(function() { //set initial state. $(‘#textbox1’).val($(this).is(‘:checked’)); $(‘#checkbox1’).change(function() { $(‘#textbox1’).val($(this).is(‘:checked’)); }); $(‘#checkbox1’).click(function() { if (!$(this).is(‘:checked’))

  • 0
$(document).ready(function() {
  //set initial state.
  $('#textbox1').val($(this).is(':checked'));

  $('#checkbox1').change(function() {
    $('#textbox1').val($(this).is(':checked'));
  });

  $('#checkbox1').click(function() {
    if (!$(this).is(':checked')) {
      return confirm("Are you sure?");
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" id="checkbox1"/><br />
<input type="text" id="textbox1"/>

Here .change() updates the textbox value with the checkbox status. I use .click() to confirm the action on uncheck. If the user selects cancel, the checkmark is restored but .change() fires before confirmation.

This leaves things in an inconsistent state and the textbox says false when the checkbox is checked.

How can I deal with the cancellation and keep textbox value consistent with the check state?

  • 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-24T11:15:06+00:00Added an answer on May 24, 2026 at 11:15 am

    Tested in JSFiddle and does what you’re asking for.This approach has the added benefit of firing when a label associated with a checkbox is clicked.

    Updated Answer:

    $(document).ready(function() {
        //set initial state.
        $('#textbox1').val(this.checked);
    
        $('#checkbox1').change(function() {
            if(this.checked) {
                var returnVal = confirm("Are you sure?");
                $(this).prop("checked", returnVal);
            }
            $('#textbox1').val(this.checked);        
        });
    });
    

    Original Answer:

    $(document).ready(function() {
        //set initial state.
        $('#textbox1').val($(this).is(':checked'));
    
        $('#checkbox1').change(function() {
            if($(this).is(":checked")) {
                var returnVal = confirm("Are you sure?");
                $(this).attr("checked", returnVal);
            }
            $('#textbox1').val($(this).is(':checked'));        
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$(document).ready(function(){ $(#CO_createAccount).click( function (){ if(this.checked){ $(.CO_accountForm).show(); } else { $(.CO_accountForm).hide(); } }); }); and
Jquery has a great language construct that looks like this: $(document).ready(function() { $(a).click(function() {
$(document).ready(function() { $(span.link).mouseover(function(e){ $(this.children).css(display,inline); }); }); I'm not a javascript expert, but I've cobbled
I want to do this, but haven't figured it quite out yet... $(document).ready(function() {
I have the following code: <script type=text/javascript> $(document).ready(function() { $(#Save).click(function() { $.post(url, { data:
I have the following: $(document).ready(function() { window.location.href='http://target.SchoolID/set?text='; }); So if someone comes to a
$(document).ready(function() { //select all the a tag with name equal to modal $('a[name=popup]').click(function(e) {
$(document).ready(function() { //select all the a tag with name equal to modal $('a[name=popup]').click(function(e) {
jQuery(document).ready(function(){ // Set the data text var dataText = { name: 'John', time: '2pm'
Can someone tell me why this doesn't work: $(document).ready(function() { $(#cookie).text(expanded); //panel toggle $(.btn-slide).click(function()

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.