473,386 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How do I get the value attribute of a radio button in C#?

I am using WebBrowser component where I display the web site.

For example:
The HTML source code which let the user choose a color:
<input type="text" name="firstname" value="the name entered by user">
<input type="radio" name="myradio" value="red">Red
<input type="radio" name="myradio" value="blue" checked>Blue
<input type="radio" name="myradio" value="white">White


In C# code (C# Application), I wanted to get the value selected by the user.
I have the below code for getting their values:

========================
HtmlDocument document = this.webBrowser1.Document;
firstName = document.All["firstname"].GetAttribute("value");
color = document.All["myradio"].GetAttribute("value");
========================

I can get the correct value from the firstname textbox, however, the "color" radio button always returns the value "red" event when Red is not selected.

Please help
Oct 27 '07 #1
2 9467
kenobewan
4,871 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. color = document.All["myradio"].GetAttribute("value");
Is only ever going to return red. Here is an alternative:
demo_radiobutton
Oct 27 '07 #2
Expand|Select|Wrap|Line Numbers
  1. color = document.All["myradio"].GetAttribute("value");
Is only ever going to return red. Here is an alternative:
demo_radiobutton
Thanks kenobewan! The alternative is good, however, it does not apply to my situation.

I have come up with a working solution below:
If there's a simpler one, i'd be happy to use it :)


HtmlDocument document = this.webBrowser1.Document;
HtmlElementCollection input = document.All.GetElementsByTagName("input");
foreach (HtmlElement element in input)
{
if (element.GetAttribute("type").ToLower() == "radio")
{
if (element.Name == "myradio" && element.GetAttribute("checked").ToLower() == "true")
color = element.Value;
}
}
Oct 29 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ed a | last post by:
Hello, I am a complete JS newbie. I am trying to make one radio button assume a certain value when another one in a different group is clicked. This is a conference registration form for which...
4
by: Randell D. | last post by:
Folks, I have a form (called FORM1) - In my INPUT submit tag, I have an onClick event that I have successfully tested/used to display the value of a TEXT box using the following function (called...
2
by: jason | last post by:
The following (likely far from imperfect code), reports a value of NaN in the j4 display. I suppose the problem is I am not really passing the "checked" value of the radio button via .value ......
4
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT...
1
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with...
5
by: johnsuth | last post by:
I want to produce a trivial demonstration of dynamic modification. I thought that pressing a button might change its color. I studied O'Reillys books and successfully created the button with a...
3
by: newjazzharmony | last post by:
Hello group, I want to automatically select a specific checkbox when a user clicks (selects) a specific item in a radiobutton group. Both controls are in the same form. Let's say for...
11
by: Jasbird | last post by:
Has the name attribute deprecated? I ask this because ASP.NET 2 warns me against using it, says that it has been deprecated and doesn't use it (on the client) when creating a radio button list....
1
by: sourcie | last post by:
I am changing an existing quiz found on "JavaScriptKit.com Multiple Choice Quiz" I have an image. Instead of using the radio buttons with the normal true/false question, I want to place two...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.