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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:06:36+00:00 2026-05-25T00:06:36+00:00

So I want to submit only when a checkbox is checked (I want to

  • 0

So I want to submit only when a checkbox is checked (I want to do something else when a checkbox is unchecked). I’ve been trying to get this checkbox submit to work but not no avail. Here’s what I have:

$('#checkbox').click(function() { 
    if ($(this).attr('checked')) {
        $("#form").submit(function () {
            var newvals = $("#form").serialize();   // serialize data

            $.post('save.php', newvals, function(data) { 
                $("#content").html(data);
            }); // posting data and dumping response onto page      

            return false;
        }); 

    } else {

        alert(2); // placeholder for what i want to do otherwise
    }

});

I looked around and was poking around with .trigger and .live, but I’m having problems even thinking about how the logic would even work with those functions. I’m not opposed to using them as long as I can distinguish between a ‘checked’ box and an ‘unchecked’ box.

Any ideas?

  • 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-25T00:06:36+00:00Added an answer on May 25, 2026 at 12:06 am

    In your code you are attaching the form submit event handler everytime you check the checkbox. It is not going to trigger the submit event and do what you are expecting.

    You should attached the submit event handler outside the click event handler of checkbox and trigger the submit event of form when checkbox is checked. Try this

    $function(){
    
        $("#form").submit(function () {
    
          var newvals = $("#form").serialize(); // serialize data
          $.post('save.php',newvals,function(data) { 
            $("#content").html(data);
          });   // posting data and dumping response onto page      
    
          return false;
        });   
    
       $('#checkbox').click(function() { 
        if(this.checked) {//Just this.checked will say whether its checked or not
            //Now trigger the form submit event
            $("#form").trigger('submit');
        } 
        else{
           alert(2); // placeholder for what i want to do otherwise
    
           //I think you want to erase the textboxes. 
           //You can find all the input elements and set there value to empty
           $("#form input").val('');
        }
       });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to submit a form only if a checkbox is checked (as opposed
I want to submit a form like this: <input type=button onclick=$('#form1').submit(); value=Create /> but
I've been trying think of a way to do this. I want it to
I want my recaptcha to appear only after user clicks submit button on the
i have a page that contains several submit buttons however i only want one
I want to submit an app to the app store. The app has been
I have a case where i want to submit a form and get the
This is something thats been hard for me to find info on, I was
I have a form which I want to submit only if a condition is
I've got a checkbox that's set up as below: <asp:CheckBox ID=myCheckbox runat=Server OnClick=showLoadingScreen(this.checked); AutoPostBack=true

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.