Client-side RadioButtonList validation

 function IsChecked()
     {
    var rblActive = document.getElementById("<%=rblActive.ClientID %>");
    var item = rblActive.getElementsByTagName("input");
    var IsItemChecked = false;
    for (var i = 0; i < item.Length; i++)
     {
        if (item[i].checked) 
        {
        IsItemChecked = true;
        }

      }
        if (IsItemChecked == false) 
          {
          alert("Check Yes or No");
          rblActive.focus();
          return false;
           }
          return true;
      }

This is the code I tried. When control comes in the for loop, it directly comes out without any action even if the item in the radio button list is checked or not checked.

Answers


You can do the same with jQuery also..

function ValidateControls() {
    var count = 0;
    $("input[type=radio]").each(function () {
        if ($(this).attr('checked')) {
            count++;
        }

    });

    if (count > 0) {
        return true;
    }
    else {
        alert("No Row Selected");
        return false;
    }
}

Need Your Help

Find multiple index in array

c# .net arrays linq

Say I have an array like this

Design implementation about the way of using HashMap

java design hashmap concurrenthashmap

When showing accounts in the GUI, I need to show primary accounts ( for secondary accounts )

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.