jquery Validation Based on RadioButtonList or TextBox Enabled

Posted by Srinivas673 under jQuery on 6/30/2011 | Points: 10 | Views : 6529 | Status : [Member] | Replies : 1
I Have one Radio Button List With 2 options 1.yes 2.No

pesonal informaion Deatails Contains:1.First Name 2.LastName 3.Email 4.Mobilenumber(i am validating alltypes of validations using jquery)


But when i select yes option from radio button list above 4 text box are disabled but those four textboxes are visible.
i select No option from radio button list above 4 text box are Enabled.

enabled case only i validate, Disable case i Dont want To Validate



my problem is when i select radiobutton list option No--I need to Validate
Yes--I dont want to validate
Now validating Both Scenarios




Responses

Posted by: Hemanthlaxmi on: 1/25/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Srinivas,

I have tried based on your requirement .Please Check this Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test Page.aspx.cs" Inherits="Test_Page" %>


<%@ Register Src="~/UserControls/TestControl.ascx" TagName="UControl" TagPrefix="UC" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js"></script>
<script type="text/javascript">
function ValidateTextBoxes(flag) {
var fName = $('input[id$=fName]');
var mName = $('input[id$=mName]');
var lName = $('input[id$=lName]');
if (flag) {
if (fName.val() != " " && fName != undefined) {
fName.attr("disabled", "disabled");
}
if (mName.val() != " " && mName != undefined) {
mName.attr("disabled", "disabled");
}
if (lName.val() != " " && lName != undefined) {
lName.attr("disabled", "disabled");
}
}
else {
if (fName.val() != " " && fName != undefined) {

fName.removeAttr("disabled");
}
if (mName.val() != " " && mName != undefined) {
mName.removeAttr("disabled");
}
if (lName.val() != " " && lName != undefined) {
lName.removeAttr("disabled");
}
}
}
$(document).ready(function () {
$('#rbtnValidate [value=true]').click(function () {
ValidateTextBoxes(true);
});
$('#rbtnValidate [value=false]').click(function () {
alert("Nothing to validate!");
ValidateTextBoxes(false);
});
});

</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
Enter First Name:
</td>
<td>
<input type="text" id="fName" />
</td>
</tr>
<tr>
<td>
Enter Middle Name:
</td>
<td>
<input type="text" id="mName" />
</td>
</tr>
<tr>
<td>
Enter Last Name:
</td>
<td>
<input type="text" id="lName" />
</td>
</tr>
<tr>
<td>
Do you want to validate?
</td>
<td>
<asp:RadioButtonList runat="server" ID="rbtnValidate">
<asp:ListItem Text="Yes" Value="true" />
<asp:ListItem Text="No" Value="false" />
</asp:RadioButtonList>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>


If this helps you .
Please "Mark as Answer"

Srinivas673, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response