Click here to Skip to main content
13,089,386 members (58,562 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi fellows,

I need your kind guidance regarding the following scenarios.

I have a section in my form which contains 1 textbox and 2 checkboxes.
I want to apply validation, that at one time only of the 3 should only be enabled and after unselecting them control could be transfered to another...

i.e. if we write some thing in checkbox then both checkboxes cant be checked and if we select any one checkbox than textbox and 2nd checkbox cant be filled.

I have applied validation on checkboxes but unable to apply on textbox completely.

problem is that when i write some thing in textbox than both textboxes got disabled but than can not be enabled again even if i do empty the textbox.

Kindly do help me in this regards.
Posted 22-Mar-13 2:51am
ThePhantomUpvoter 22-Mar-13 9:00am
Help with what exactly? How would you expect us to know what it is that you have done when you do not post your code?
ryanb31 22-Mar-13 9:01am
How can we help if we can't see the code?
Khan Ji 25-Mar-13 6:04am
Hi Guys.. there is a possibility some time, when code cant be pasted due to some reasons. That's y i tried to clear my problem through words.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


I have come with a small prototype. Let me know if it works for you.
<!DOCTYPE html>
<script src=""></script>
<script type="text/javascript">
function enforce(ctrl) {
    if ( === "txtName") {
        $('#chkOne').prop("disabled", ctrl.value.length > 1);
        $('#chkTwo').prop("disabled", ctrl.value.length > 1);
    else if ( === "chkOne") {
        $('#txtName').prop("disabled", ctrl.checked);
        $('#chkTwo').prop("disabled", ctrl.checked);
    else {
        $('#txtName').prop("disabled", ctrl.checked);
        $('#chkOne').prop("disabled", ctrl.checked);
    <form id="frmMain" name="frmMain" method="post">
Name        : <input type="text" id="txtName" name="txtName" onChange="enforce(this);"/>
Nationality : <input type="checkbox"  id="chkOne" name="chkOne" value="O" onChange="enforce(this);"/>One
              <input type="checkbox"  id="chkTwo" name="chkTwo" value="T" onChange="enforce(this);"/>Two

Khan Ji 25-Mar-13 6:03am
Thanks Prasad for helping me out.. your post give me a gud idea to solve but problem was that i am using controls and they have different events against them. well finally googling more problem got solved. :)
Prasad Khandekar 25-Mar-13 6:30am
I am glad that to know that your problem got solved. Even if you use controls on the client side it's still HTML and so the solution I proposed helps you do it without doing a postback.
Khan Ji 26-Mar-13 3:48am
ya u r ryt...but there is much difference in the events used by HTML controls and asp controls. for exmple onChange event which u mentioned in solution does not exist for asp checkbox..m i ryt???

actually m totally new to this field so concepts are nt cleard pretty do correct if i m on mistake...thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 22 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100