Solved

ASP.Net change radio button via javascript from onblur attribute

Posted on 2009-07-09
6
1,017 Views
Last Modified: 2012-05-07
Please help. I have a radio button group with two buttons and one text box. If the user clicks into and then out of the text box I want to check if the user has changed the value from the default (which is 0) and if the user has changed the value I want the radio button to automatically switch to yes (which is the second item in the radio button group index).

I added the onblur attribute to my textbox and have tried to get the javascript going with all sorts of methods to no avail...

tbxBid.Attributes.Add("onblur", String.Format("CheckBoxChange(this.value,{0},{1});", tbxBox.ClientID, rdbGroup.ClientID))
 

    <script type="text/javascript">

        function CheckManualEntry(value, txtBoxName, rdbName) {

            var old_price = txtBoxName.getAttribute("value");

            var rb = document.getElementsByName(rdbName);

            rb[1].checked = true;

        }

    </script>

Open in new window

0
Comment
Question by:mrferrari
  • 2
  • 2
  • 2
6 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 24817957

set your autopostback to true.
add an ontextchanged event handler.
AJAX it.
0
 

Author Comment

by:mrferrari
ID: 24817975
I want to use javasciprt. this is really small and simple. i cant figure it out though.

I don't want the page to autopostback...
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 24818103
http://dotnetslackers.com/articles/aspnet/JavaScript_with_ASP_NET_2_0_Pages_Part1.aspx

tbxBid.Attributes.Add("onblur",   PASTE_FUNCTION_HERE)

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 20

Expert Comment

by:ddayx10
ID: 24819717
I don't understand the scope beyond just the basics you outlined. I was a little confused by your attribute assignment in the code behind because you were calling on ID's that you hadn't mentioned in your question (tbxBid and tbxBox). All that is to say I may have missed the mark because I had to simplify without having more information...

Anyway this should give you an idea of how to begin managing the situation. I just wrote something that addresses the very specific things you mentioned. Of course I imagine you have a bigger scope and will have to update it accordingly...
0
 
LVL 20

Accepted Solution

by:
ddayx10 earned 500 total points
ID: 24819725
didn't mean to post that (just hit the enter key on accident)...see snippet
****ASPX CODE****

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Change RadioButton</title>

    <script type="text/javascript">

		function CheckBoxChange(txtBx, rblID)

		{

			if(txtBx.value != '0')

			{

				var rblParent = document.getElementById(rblID);

				var rbl = rblParent.getElementsByTagName('input');

				rbl[0].checked = true;

			}

		}

    </script>

</head>

<body>

    <form id="form1" runat="server">
 

		<span>Default Text Box</span>

		<asp:TextBox ID="tbxBid" runat="server" Text="0" />
 

		<asp:RadioButtonList ID="rdbGroup" runat="server">

			<asp:ListItem Value="0" Text="Yes" />

			<asp:ListItem Value="1" Text="No" />

		</asp:RadioButtonList>

		

		

    </form>

</body>

</html>
 
 

****CODE BEHIND****

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 

        If Not IsPostBack Then

            'Keep in mind that if you are using an asp:radiobuttonlist then the tdbGroup.clientID you are sending below

            'is actually a table, and you have to use that to get at the radiobuttons inside

            tbxBid.Attributes.Add("onblur", String.Format("CheckBoxChange(this,'{0}');", rdbGroup.ClientID))

        End If
 

    End Sub

Open in new window

0
 

Author Comment

by:mrferrari
ID: 24825248
bingo bango... that works great. thanks so much...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now