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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:43:48+00:00 2026-05-24T19:43:48+00:00

I have a few checkboxes in my form and I need to change their

  • 0

I have a few checkboxes in my form and I need to change their value when the checkbox is checked.

For example this is one of the checkboxes:

<input type="checkbox" name="drink" value=""/>

I know .val() can change it but I wasn’t able to do this with if statement.

I appreciate your answer in advance.

  • 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-24T19:43:49+00:00Added an answer on May 24, 2026 at 7:43 pm
    // attach an onchange handler to all checkboxes on the page
    $("input[type='checkbox']").change(function() {
    
        // or if($(this).prop("checked")) {
        if(this.checked) {
            $(this).val("value for checked");
        } else {
            $(this).val("value for unchecked");
        }
    });
    
    • The onchange event is the one you should be interested when it comes to checkboxes, as it fires whenever you change the checked state of it.
    • The checked property determines whether or not the checkbox has been checked.
    • The .val() method allows you to conveniently read/write element values.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a few checkboxes like the following: <input type=checkbox onchange=foo(bar); /> Bar
Here's the scenario: I have a contact form with few checkboxes: <input type=text name=cola[]
I have a form with thousands of checkboxes, and when one is checked, I
I have a few checkboxes that submit and change an attribute's value on my
i have form in drupal which uploads images and has got few checkboxes in
I have a basic PHP form (a few fields and 2 checkboxes, I want
I have a small html form with three checkboxes, one in each row .
I have a jqxGrid which I have a few checkboxes in. What I need
I have created a PreferenceScreen with a few checkboxes. One of them is: <CheckBoxPreference
I have this contact form which also relates to a few other tables with

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.