<script type="text/javascript">
function ChkBoxCheckChange2() {
var CHK1 = document.getElementById("<%=chkinterest.ClientID%>");
var checkbox1 = CHK1.getElementsByTagName("input");
var label = CHK1.getElementsByTagName("label");
var counter = 0;
for (var i = 0; i < checkbox1.length; i++) {
if (checkbox1[i].checked) {
if (label[i].innerHTML == "Others, please specify") {
document.getElementById("divorgprimary").style.display = (label[i].innerHTML == "Others, please specify") ? "block" : "none";
}
else {
document.getElementById("divorgprimary").style.display = (label[i].innerHTML == "Others, please specify") ? "none" : "none";
}
}
else {
document.getElementById("divorgprimary").style.display = (label[i].innerHTML == "Others, please specify") ? "none" : "none";
}
}
}
function ValidateModuleList1(source, args) {
var chkListModules = document.getElementById('<%= chkinterest.ClientID%>');
var chkListinputs = chkListModules.getElementsByTagName("input");
for (var i = 0; i < chkListinputs.length; i++) {
if (chkListinputs[i].checked) {
args.IsValid = true;
return;
}
}
args.IsValid = false;
}
</script>
<div>
<asp:CheckBoxList ID="chkinterest" runat="server" onclick="ChkBoxCheckChange2(this)"
RepeatColumns="2" RepeatDirection="Horizontal">
<asp:ListItem Value="A" Text="A"></asp:ListItem>
<asp:ListItem Value="B" Text="B"></asp:ListItem>
<asp:ListItem Value="C" Text="C"></asp:ListItem>
<asp:ListItem Value="D" Text="D"></asp:ListItem>
<asp:ListItem Value="Others, please specify">Others, please specify</asp:ListItem>
</asp:CheckBoxList>
<asp:CustomValidator runat="server" ID="CustomValidato1" ClientValidationFunction="ValidateModuleList1"
ErrorMessage="Required!" Display="Dynamic"><span style="color:Red;">Required!</span></asp:CustomValidator>
<div id="divorgprimary" style='display: none'>
Others
<asp:TextBox ID="txtinterest" Width="200px" runat="server" MaxLength="50"></asp:TextBox>
</div>
</div>
code----
string prodInterest = string.Empty;
foreach (ListItem list in chkinterest.Items)
{
if (list.Selected)
{
if (prodInterest == "" || prodInterest == null)
{
if (list.Value == "Others, please specify")
prodInterest = txtinterest.Text;
else
prodInterest = list.Value;
}
else
{
if (list.Value == "Others, please specify")
prodInterest = prodInterest + "," + txtinterest.Text;
else
prodInterest = prodInterest + "," + list.Value;
}
}
}
function ChkBoxCheckChange2() {
var CHK1 = document.getElementById("<%=chkinterest.ClientID%>");
var checkbox1 = CHK1.getElementsByTagName("input");
var label = CHK1.getElementsByTagName("label");
var counter = 0;
for (var i = 0; i < checkbox1.length; i++) {
if (checkbox1[i].checked) {
if (label[i].innerHTML == "Others, please specify") {
document.getElementById("divorgprimary").style.display = (label[i].innerHTML == "Others, please specify") ? "block" : "none";
}
else {
document.getElementById("divorgprimary").style.display = (label[i].innerHTML == "Others, please specify") ? "none" : "none";
}
}
else {
document.getElementById("divorgprimary").style.display = (label[i].innerHTML == "Others, please specify") ? "none" : "none";
}
}
}
function ValidateModuleList1(source, args) {
var chkListModules = document.getElementById('<%= chkinterest.ClientID%>');
var chkListinputs = chkListModules.getElementsByTagName("input");
for (var i = 0; i < chkListinputs.length; i++) {
if (chkListinputs[i].checked) {
args.IsValid = true;
return;
}
}
args.IsValid = false;
}
</script>
<div>
<asp:CheckBoxList ID="chkinterest" runat="server" onclick="ChkBoxCheckChange2(this)"
RepeatColumns="2" RepeatDirection="Horizontal">
<asp:ListItem Value="A" Text="A"></asp:ListItem>
<asp:ListItem Value="B" Text="B"></asp:ListItem>
<asp:ListItem Value="C" Text="C"></asp:ListItem>
<asp:ListItem Value="D" Text="D"></asp:ListItem>
<asp:ListItem Value="Others, please specify">Others, please specify</asp:ListItem>
</asp:CheckBoxList>
<asp:CustomValidator runat="server" ID="CustomValidato1" ClientValidationFunction="ValidateModuleList1"
ErrorMessage="Required!" Display="Dynamic"><span style="color:Red;">Required!</span></asp:CustomValidator>
<div id="divorgprimary" style='display: none'>
Others
<asp:TextBox ID="txtinterest" Width="200px" runat="server" MaxLength="50"></asp:TextBox>
</div>
</div>
code----
string prodInterest = string.Empty;
foreach (ListItem list in chkinterest.Items)
{
if (list.Selected)
{
if (prodInterest == "" || prodInterest == null)
{
if (list.Value == "Others, please specify")
prodInterest = txtinterest.Text;
else
prodInterest = list.Value;
}
else
{
if (list.Value == "Others, please specify")
prodInterest = prodInterest + "," + txtinterest.Text;
else
prodInterest = prodInterest + "," + list.Value;
}
}
}



0 comments:
Post a Comment