Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a problem while calling client side function on button click..Its working fine in my local system but not wrkng in server...I used set of radio buttons with name 'credrad' inside one form by name 'frmMain'..i Wrote some radiobutton validation in javascript..When I update my files to ftp its not executing that validation function only..Its throwing some error...
'document.frmMain.credrad' is null or not an object
why is it so in server...Below is my javascript function

C#
if((document.frmMain.credrad[0].checked=="")&&(document.frmMain.credrad[1].checked=="")&&(document.frmMain.credrad[2].checked=="")&&(document.frmMain.credrad[3].checked==""))
     {
    alert ('Select Your Credit Card');
     return false;
     }
Posted
Comments
Radhika Vyas 7-Nov-12 2:26am    
HI...Thanx for ur quick response but I need to do many validations at my client click side...Depending on selected radio button diff functionality i need to apply..so can u provide diff approach

you can try following javascript funtion :

JavaScript
function CheckRadioButton() {
            var radio = document.getElementsByName('YourRadioButtonList');
            var rFlag = 0;
            if (radio.length > 0)
            {
                for (var j = 0; j < radio[0].cells.length; j++) {
                    for (var k = 0; k < radio[0].cells[j].children.length; k++) {
                        if (radio[0].cells[j].children[k].checked == true)
                        {
                            rFlag = 1;
                        }                        
                    }
                }
            }
            if (rFlag == "0") {
                alert('Please Select');
                return false;
            } 
            return true;
        }
 
Share this answer
 
using jquery you can do it in this way.


JavaScript
<script type="text/javascript">
        $(document).ready(function () {           
            $("#Button2").click(function () {
                alert(checkList());
            });
        });
        function checkList() {
            var flag = true;
            $("input[id*='CheckBoxList1']").each(function () {
                if (!$(this).is(":checked"))
                    flag = false;
            });
            return flag;
        }    
    </script>



ASP.NET
<div>
  <asp:checkboxlist id="CheckBoxList1" runat="server" xmlns:asp="#unknown">
      <asp:listitem>select all</asp:listitem>
      <asp:listitem>a</asp:listitem>
      <asp:listitem>b</asp:listitem>
      <asp:listitem>c</asp:listitem>
      <asp:listitem>d</asp:listitem>
  </asp:checkboxlist>
  <input id="Button2" type="button" value="button" />
</div>
 
Share this answer
 

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