Create a Alert Function for Radio button on asp page

I have to many events going on tis page already, I would like to create a Alert function for when a user only selects the radio button that has a value of 4 and then alerts them to a message.
Still using asp.net 1.1 so I am hoping I can do it on a OnSelectedIndexChanged event on the HTML side of the house.

<td width="30%"><asp:radiobuttonlist id="rbDutyStatus" Runat="server" TextAlign="Right" RepeatLayout="Flow" RepeatDirection="Horizontal" Font-Bold="True" AutoPostBack="True" OnSelectedIndexChanged="javascript:selectRB();">
                                          <asp:ListItem Value="0">VSI&nbsp;&nbsp;</asp:ListItem>
                                          <asp:ListItem Value="1">SI&nbsp;&nbsp;</asp:ListItem>
                                          <asp:ListItem Value="2">NSI&nbsp;&nbsp;</asp:ListItem>
                                          <asp:ListItem Value="3">RTD-L&nbsp;&nbsp;</asp:ListItem>
                                          <asp:ListItem Value="4">RTD&nbsp;&nbsp;</asp:ListItem>
                                    </asp:radiobuttonlist>
Here is the function I created but it does not work.  Very limited knowledge of Javascript.

function selectRB() {
			var rbCount;
			
			if document.frm.rbDutyStatus.checked = "4" then
				Alert("Status Will Change")
						
				}
			}

Open in new window

kdeutschAsked:
Who is Participating?
 
RajasekaranMoorthyCommented:
//Server Control

<asp:radiobuttonlist id="rbDutyStatus" Runat="server" TextAlign="Right" RepeatLayout="Flow" RepeatDirection="Horizontal" Font-Bold="True" onclick="return selectRB();">
      <asp:ListItem Value="0">VSI&nbsp;&nbsp;</asp:ListItem>
      <asp:ListItem Value="1">SI&nbsp;&nbsp;</asp:ListItem>
      <asp:ListItem Value="2">NSI&nbsp;&nbsp;</asp:ListItem>
      <asp:ListItem Value="3">RTD-L&nbsp;&nbsp;</asp:ListItem>
      <asp:ListItem Value="4">RTD&nbsp;&nbsp;</asp:ListItem>
    </asp:radiobuttonlist>


//Javascript Function

function selectRB()
    {
        var rdoList = document.getElementById('rbDutyStatus');
        var rdoListCount= rdoList.getElementsByTagName("input");
       
        for(var i=0;i<rdoListCount.length;i++)
        {
            if(( rdoListCount[i].checked ) && (rdoListCount[i].value == "4") )
            {
                  alert('You selected RTD');  
            }
        }
       return false;
    }
0
 
Gurvinder Pal SinghCommented:
replace
if document.frm.rbDutyStatus.checked = "4"

by
document.frm.rbDutyStatus.selectedIndex == 4
0
 
leakim971PluritechnicianCommented:
Hello kdeutch,

Try :

function selectRB() {
   var rbCount;
   if(document.getElementById("rbDutyStatus").options[document.getElementById("rbDutyStatus").selectedIndex].value=="4")
       alert("Status Will Change")
}

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
kadabaCommented:
or perhaps

OnSelectedIndexChanged="javascript:selectRB(this);">

and then have

function selectRB(radObj) {
   var rbCount;
   if(radObj.options[radObj.selectedIndex].value=="4")
       alert("Status Will Change");
}
reason being the control being a server side control might generate a different client id.
0
 
kdeutschAuthor Commented:
Hi,
Ok when I try to view the page it gives me this error.
Compilation Error
But when i take of the last part to the radio button  (OnSelectedIndexChanged="javascript:selectRB();">)
the error goes away.

<asp:radiobuttonlist id="rbDutyStatus" Runat="server" TextAlign="Right" RepeatLayout="Flow" RepeatDirection="Horizontal" Font-Bold="True"  OnSelectedIndexChanged="javascript:selectRB();">
0
 
Carl TawnSystems and Integration DeveloperCommented:
Thats because you are attempting to attach a client-side javascript function as the handler for a server-side event.
0
 
kdeutschAuthor Commented:
Forgot this part of message

Compiler Error Message: BC30456: 'javascript' is not a member of 'ASP.HealthForm_aspx'.
0
 
kdeutschAuthor Commented:
All,

ok I need to get the value on code behind to properly make inserts into the DB,  Is there any way to make this work or do i just need to use server side mechanisims.
0
 
kadabaCommented:
@RajasekaranMoorthy:

Asp is my weaker side :) so bear with me if i ask something wrong.
should this not be onclientclick="return selectRB();"> instead of onclick="return selectRB();">
as the functionality is on the client side.

also would it not make sense if we send "this" the object itself to the function and then check for the value.
0
 
kdeutschAuthor Commented:
Hi,
Ok back from some needed time off.
I tried all solutions but came back around to just using the server side postback on this, don't have the time to test it anymore.
Treid all these but none where working with any of them.
onclientclick
OnClick
OnSelectedIndexChanged
OnClientSelectedIndexChanged
0
 
kdeutschAuthor Commented:
Gave points for help, time to move on
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.