Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 11-Dec-12 0:35am
v2
Comments
choudhary.sumit 11-Dec-12 5:35am    
are you working on web application or a desktop application?
[no name] 11-Dec-12 7:06am    
Can you tell me How you want to do this operation using jquery or C#?
hardy panchal 11-Dec-12 7:13am    
I am working on Web Application
[no name] 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;
}
}

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

1 solution

$(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');
}
}

});
 
Share this answer
 
Comments
[no name] 11-Dec-12 8:39am    
This should not be in Document.ready().
As in the beginning the radio buttons will never be checked. So instead of using the validate function in document.ready() you can use that in separate function and use that on a button click event by simply calling onClientClick().

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900