Click here to Skip to main content
12,999,633 members (40,480 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Suppose I have 2 Radio Button and and 4 textbox and 1 Button If i 1st radio button is select then it allow 3rd and 4th textbox allow to be null.(it fire validation on textbox 1 and textbox 2) and if i select radio buttoon 2 then it allow 1st and 2nd textbox allow to be null (it fire validation on textbox 3 and textbox 4)

its whole happend when i Click on Button .Please help Me.
Thanks in Advance
Posted 10-Dec-12 23:27pm
Updated 11-Dec-12 0:35am
choudhary.sumit 11-Dec-12 5:35am
are you working on web application or a desktop application?
hardy panchal 11-Dec-12 7:13am
I am working on Web Application
shabari7 11-Dec-12 7:14am
********Assumptions:WebForm,individual radio buttons with same groupname,one is checked by default.

code behind, in !ispostback

btnSubmit.attributes.add("onclick","return javascript:fnValidate()");

in aspx script tag

function fnValidate()
var radTwo = document.getelementbyid('radOneid');
var txtOneId = document.getelementbyid('txtOneId');
var txtTwoId = document.getelementbyid('txtTwoId');
var txtThreeId= document.getelementbyid('txtThreeId');
var txtFourId= document.getelementbyid('txtFourId');
if(txtThreeId.value=="" && txtFourId.value=="")
alert('Text 3 and 4 are required');
return flase;
if(txtOneId.value=="" && txtTwoId.value=="")
alert('Text 1 and 2 are required');
return false;

Milind_T 11-Dec-12 7:17am
@shabari7: Why in comment, please post as solution.

1 solution

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

Solution 1


if($('#txt3').val()=="" ||$('#txt4').val()=="")
alert('This textbox should not be null');

else if($('#rbt2').is('checked')==true)
if($('#txt1').val()=="" ||$('#txt2').val()=="")
alert('This textbox should not be null');


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 | Mobile
Web02 | 2.8.170624.1 | Last Updated 11 Dec 2012
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