JavaScript - Radio button list

Asked By samantha jyesta
09-Dec-11 03:46 AM


Hi 

I have a Radio button list in my page . After placing that i have placed some other controls.
I need javascript for the radio button list while the user doesn't select any one option in radio button list , i need to show one alert messgae like please select any option in radio button list.



How can i do this.



Cheers,
Samantha.
  Vickey F replied to samantha jyesta
09-Dec-11 03:50 AM
Use this client side function-

function Check()

      {
     var RadioList= document.getElementById ('<%= boxid.ClientID %>');
       for(var i=0;i<RadioList.length;i++)
      {  
        if(RadioList[i].checked)
        {
       document.getElementById ('<%= boxid.ClientID %>').disabled=True;
       }
      }
      } 

This this code and let me know.
  dipa ahuja replied to samantha jyesta
09-Dec-11 03:51 AM
<script type="text/javascript">
 
  function checkSelection() {
    var listItemArray = document.getElementsByName('<%= RadioButtonList1.ClientID %>');
    
    var isItemChecked = false;
    
    //Radio check
    for (var i = 0; i < listItemArray.length; i++) {
      var listItem = listItemArray[i];
      if (listItem.checked) {
        isItemChecked = true;
      }
    }
         if (isItemChecked == false) {
      alert('Check atleast one item!');
      return false;
    }
    return true;
  
  }
</script>
 
<asp:RadioButtonList ID="RadioButtonList2" runat="server"
  AutoPostBack="True">
  <asp:ListItem>Yes</asp:ListItem>
  <asp:ListItem>No</asp:ListItem>
</asp:RadioButtonList>

  Suchit shah replied to samantha jyesta
09-Dec-11 04:17 AM
Suppose you have 3 Radiobuttons.. You will be validating on some button control. Please find below how to do it step by step.

Step1: Setup your radio buttons on aspx page.

<strong> Some Heading</strong>

 

<asp:RadioButtonID="Radio1"GroupName="Flag"runat="server"Text="DNR"/>&nbsp;

<asp:RadioButtonID="Radio2"GroupName="Flag"runat="server"Text="RE"/>&nbsp;

 

<asp:RadioButtonID="Radio3"GroupName="Flag"runat="server"Text="RI"/>

Step2: You have to declare some button/imagebutton or somthing else to validate. I suppose you have button cmdSave for validation.

Step3: in code behind of page On Page Load, you have to call javascript function of validation. i.e

cmdSave.Attributes.Add(

"onClick","Javascript:checkFlag()");

Step4: You have to declare function checkFlag() in your aspx page. i.e

function

checkFlag()

{

 

event.returnValue =false;

 

var DNR = document.getElementById('<%= RadioDNR.ClientID %>').checked;

 

var RE = document.getElementById('<%= RadioRE.ClientID %>').checked;

 

var RI = document.getElementById('<%= RadioRI.ClientID %>').checked;

 

if (DNR == false && RE == false && RI ==false)

{

alert (

'Please Specify one of the Flags');

}

 

else

{

 

event.returnValue =true;

}

}

You have to do nothing else. I am sure it will resolve your problem. If this is the solution of your problem, please mark this post as resolved. Thanks

  Anoop S replied to samantha jyesta
09-Dec-11 05:37 AM
try this


<script type="text/javascript">
<!--
function onButtonClick()
{
 return validateRadioButtonList('<%= RadioButtonList1.ClientID %>');
}
function validateRadioButtonList(radioButtonListId)
{
 var listItemArray = document.getElementsByName(radioButtonListId);
 var isItemChecked = false;

 for (var i=0; i<listItemArray.length; i++)
 {
  var listItem = listItemArray[i];

  if ( listItem.checked )
  {
   //alert(listItem.value);
   isItemChecked = true;
  }
 }

 if ( isItemChecked == false )
 {
  alert('Nothing is checked!');

  return false;
 }

 return true;
}
// -->
</script>

Create New Account
help
Session Issues hi. . . . I have two page "Landing page" and "Home page" . . I declare session on landing page. . . and pop up one light box on landing page load. . in that light box accept button is created. . when i click on accept button it redirect to "home page" . . after come on home page if i click on Back button of browser , i want that it should not redirect
Refresh page code not working I was looking for a way to handle refreshes (user pressed refresh button) and found a piece of code to check if a Web page was refreshed but I can't get it to work. The code is: * ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** * Namespace StevenBey Web.UI Public Class Page Inherits System.Web.UI.Page Private _refreshState As Boolean Private _isRefresh As Boolean Public ReadOnly Property IsRefresh() As Boolean Get allStates(0) = MyBase.SaveViewState() allStates(1) = Not _refreshState Return allStates End Function 'SaveViewState End Class 'Page End NameSpace * ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** * If I do a: trace.warn("is Refresh = " & Page.IsRefresh) or trace.warn("is Refresh = " & IsRefresh) I get the error: BC30456 'IsRefresh' is not a member of 'System.Web.UI.Page' I took the compiled version (StevenBey.Web.UI.dll) and put it in my Bin
what is AutoEventWireup please tell me the importance of AutoEventWireup in every aspx page. what it does. if i remove it then what will happen? the ASP.NET page framework also supports an automatic way to associate page events and methods. If the AutoEventWireup attribute of the Page directive is set to true (or if it is missing, since by default it is true ), the page framework calls page events automatically, specifically the Page_Init and Page_Load methods. In that case, no explicit Handles clause delegate is needed. The disadvantage of the AutoEventWireup attribute is that it requires that the page event handlers have specific, predictable names. This limits your flexibility in how you name your attribute is set to false by default and the designer generates explicit code to bind page events to methods. If you do set AutoEventWireup to true , Visual Studio will generate code
bit = 0, @Payments int OUTPUT, @TotalPaid Money OUTPUT ) AS SET NOCOUNT ON; / * Misc work areas * / Declare @RunDate DateTime Declare @YYYYMMDD Char(8) Declare @YYDDD Char(5) Declare @DDD Char(3) Declare @FiscalYear Char(4) Declare @RunDay Int Declare @MonthStart DateTime Declare @MonthEnd DateTime Declare @LastRun DateTime Declare @VendorName Varchar(30) Declare @VendorNameAlternate Varchar(15) Declare @BankAccountPerson
Varables from .ASP to .ASP page C++ / VB I have an .ASP page that comes up, and I am trying retrieve a variable from the previous .ASP page. However none of the variables from the previous .ASP page are available to the current .ASP page. There are three pages in this chain. 1. NewUser.html Information is input in this page, and posted to the next page using this tag <form method = "post" action = "newUser_response.asp"> . 2. NewUser_response.asp Information is retrieved from the previous page using the using the <form method = "post" action = "newUser.asp"> This page is basically just