Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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
Edited 11-Dec-12 0:35am
v2
Comments
choudhary.sumit at 11-Dec-12 5:35am
   
are you working on web application or a desktop application?
hardy panchal at 11-Dec-12 7:13am
   
I am working on Web Application
shabari7 at 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(radTwo.checked)
{
if(txtThreeId.value=="" && txtFourId.value=="")
{
alert('Text 3 and 4 are required');
return flase;
}
}
else
{
if(txtOneId.value=="" && txtTwoId.value=="")
{
alert('Text 1 and 2 are required');
return false;
}
}
 
}
Milind_T at 11-Dec-12 7:17am
   
@shabari7: Why in comment, please post as solution.

1 solution

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

Solution 1

$(document).ready(function(){
 
if($('#rbt1').is('checked')==true)
{
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');
}
}
 
});
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,649
1 Sergey Alexandrovich Kryukov 6,280
2 CPallini 5,230
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140921.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2014
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