[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Create a Alert Function for Radio button on asp page

Posted on 2009-12-23
11
Medium Priority
?
364 Views
Last Modified: 2012-05-08
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

0
Comment
Question by:kdeutsch
11 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 26112447
replace
if document.frm.rbDutyStatus.checked = "4"

by
document.frm.rbDutyStatus.selectedIndex == 4
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26112537
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
 
LVL 22

Assisted Solution

by:kadaba
kadaba earned 200 total points
ID: 26112595
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kdeutsch
ID: 26112600
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
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 200 total points
ID: 26112619
Thats because you are attempting to attach a client-side javascript function as the handler for a server-side event.
0
 

Author Comment

by:kdeutsch
ID: 26112628
Forgot this part of message

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

Author Comment

by:kdeutsch
ID: 26112695
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
 
LVL 1

Accepted Solution

by:
RajasekaranMoorthy earned 600 total points
ID: 26117469
//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
 
LVL 22

Expert Comment

by:kadaba
ID: 26117486
@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
 

Author Comment

by:kdeutsch
ID: 26153322
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
 

Author Closing Comment

by:kdeutsch
ID: 31669417
Gave points for help, time to move on
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month17 days, 15 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question