I have two checkboxes on my form; chkBuried
and chkAboveGround
. I want to set it up so if one is checked, the other is unchecked. How can I do this?
I have tried the CheckChanged
property:
private void chkBuried_CheckedChanged(object sender, EventArgs e)
{
chkAboveGround.Checked = false;
}
private void chkAboveGround_CheckedChanged(object sender, EventArgs e)
{
chkBuried.Checked = false;
}
And it works, just not as well as I hoped. That is, when I check chkBuried
, then check chkAboveGround
, both boxes become unchecked before I can check another one again.
Here's one approach: import React from "react"; import ReactDOM from "react-dom"; class App extends React. Component { // some example state state = { a: { curr: false, prev: false, disabled: false }, b: { curr: false, prev: false, disabled: false }, c: false }; toggleOthers = () => { if (this.
Note: If a checkbox is unchecked when its form is submitted, there is no value submitted to the server to represent its unchecked state (e.g. value=unchecked ); the value is not submitted to the server at all.
prop() and is() method are the two way by which we can check whether a checkbox is checked in jQuery or not. prop(): This method provides an simple way to track down the status of checkboxes. It works well in every condition because every checkbox has checked property which specifies its checked or unchecked status.
modify your code as below.
private void chkBuried_CheckedChanged(object sender, EventArgs e)
{
chkAboveGround.Checked = !chkBuried.Checked;
}
private void chkAboveGround_CheckedChanged(object sender, EventArgs e)
{
chkBuried.Checked = !chkAboveGround.Checked;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With