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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:01:10+00:00 2026-06-17T00:01:10+00:00

I have a small html form with three checkboxes, one in each row .

  • 0

I have a small html form with three checkboxes, one in each row. I want to have a javascript confirm box show when the user unchecks the box, and then if the user selects cancel, the checkbox remains checked. I’ve searched this site and a few others but almost everything was to do with the checkbox being checked, like if they had to agree to some terms or something. I am very new to Javascript however I tried to make a function based on what I though it should look like, but it doesn’t work.

Here is my form:

<form action="" method="post">
  <table id="table">
    <tr>
      <td>Checkbox One</td>
      <td align="center">
        <input type="checkbox" name="check1" checked="checked" onchange="cTrig(this.name)"></input>
      </td>
    </tr>
    <tr>
      <td>Checkbox Two</td>
      <td align="center">
        <input type="checkbox" name="check2" checked="checked" onchange="cTrig(this.name)"></input>
      </td>
    </tr>
    <tr>
      <td>Checkbox Three</td>
      <td align="center">
        <input type="checkbox" name="check3" checked="checked" onchange="cTrig(this.name)"></input>
      </td>
    </tr>
    <tr align="center">
      <td colspan="2">
        <input type="submit" name="submit" value="submit"></input>
      </td>
    </tr>
  </table>
</form>

And here is the function I tried, but doesn’t work:

function cTrig(name) {
  if (name.checked == true) {
    confirm("Are you sure you want to do this?");
    return true;
  } else {
    return false;
  }
}

Here is a jsfiddle

I would prefer something in Javascript as I want to become more familiar with that language before getting into jquery, but if it has to be done in jquery, then that is fine. Cheers.

  • 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-06-17T00:01:11+00:00Added an answer on June 17, 2026 at 12:01 am

    Try This Way

    <form action="" method="post">
      <table id="table">
        <tr>
          <td>Checkbox One</td>
          <td align="center">
            <input type="checkbox" name ="check1" id="check1" checked='checked' onchange="cTrig('check1')"></input>
          </td>
        </tr>
        <tr>
          <td>Checkbox Two</td>
          <td align="center">
            <input type="checkbox" name="check2" id="check2" checked='checked' onchange="cTrig('check2')"></input>
          </td>
        </tr>
        <tr>
          <td>Checkbox Three</td>
          <td align="center">
            <input type="checkbox" id="check3" name="check3" checked='checked' onchange="cTrig('check3')"></input>
          </td>
        </tr>
        <tr align="center">
          <td colspan="2">
            <input type="submit" name="submit" value="submit"></input>
          </td>
        </tr>
      </table>
    </form>
    

    By Using Element Id

    function cTrig(clickedid) { 
          if (document.getElementById(clickedid).checked == true) {
            return false;
          } else {
           var box= confirm("Are you sure you want to do this?");
            if (box==true)
                return true;
            else
               document.getElementById(clickedid).checked = true;
    
          }
        }
    

    Working Demo

    By Using Name

    function cTrig(clickedid) { 
          if (document.getElementsByName(clickedid)[0].checked == true) {
            return false;
          } else {
           var box= confirm("Are you sure you want to do this?");
            if (box==true)
                return true;
            else
               document.getElementsByName(clickedid)[0].checked = true;
    
          }
        }
    

    Demo Using element name

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

Sidebar

Related Questions

I have this small snippet to change a bit of html when a user
I have a table in an ASP.NET MVC2 form. On each row in the
i have made a small web application with form.html output.jsp ServletOne.java In the form.html,users
I have a .Net application that dynamically creates a small HTML page and pops
I have a small helper app that I use to inject scripts into html
I have a small, custom crafted HTML report, not using any reporting engine, for
I have a string which holds a small amount of HTML generated content. I
I have docbook generated HTML that contains small, fixed size images. All these images
I have a small list of checkboxes (see below), and I noticed I can
I have a pretty standard html form with a few input boxes. I have

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.