473,387 Members | 1,536 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,387 software developers and data experts.

reset radiobuttonlist in javascript

how do i reset radiobuttonlist in javascript

i need to reset radiobuttonlist on click of a hyperlink
i have written the code as
document.getElementById('rblOffshoreFamiliarity'). selectedIndex=0;
document.getElementById('rblOffshoreFamiliarity'). value=1;
document.getElementById('rblOffshoreFamiliarity'). value=options[-1];

none of this is working

can u guyz help me out with this
Jul 19 '07 #1
10 7386
acoder
16,027 Expert Mod 8TB
Do you only want to reset the radio buttons or everything on the form? If you don't mind resetting everything, just use the form's reset() method.
Jul 19 '07 #2
gits
5,390 Expert Mod 4TB
hi ...

in case you want only the radios resetted have a look at the following example:

[HTML]<html>
<head>
<script>
function reset_radio_grp() {
var rgrp = document.getElementsByName('rblOffshoreFamiliarity ');
rgrp[0].checked = 'checked';
}
</script>
</head>
<body>
<form name="my_form">
<input type="radio" name="rblOffshoreFamiliarity" value="1" checked="checked"/>
<input type="radio" name="rblOffshoreFamiliarity" value="2"/>
<input type="radio" name="rblOffshoreFamiliarity" value="3"/>
<input type="button" value="reset radio group" onclick="reset_radio_grp();"/>
</form>
</body>
</html>
[/HTML]

kind regards
Jul 19 '07 #3
acoder
16,027 Expert Mod 8TB
hi ...

in case you want only the radios resetted have a look at the following example:
Yes, I thought I might as well take the simple approach first.

However, isn't a set of radio buttons normally unchecked?
Jul 19 '07 #4
gits
5,390 Expert Mod 4TB
hi ...

at the w3c-html-spec you find the following in the radio-buttons section:

At all times, exactly one of the radio buttons in a set is checked. If none of the <INPUT> elements of a set of radio buttons specifies `CHECKED', then the user agent must check the first radio button of the set initially.
Since user agent behavior differs, authors should ensure that in each set of radio buttons that one is initially "on".
so i think one radio-button should be checked initially ... since FF is not doing we have to specify it for ourselves ... in case i get what the spec says? ... i think this is to do, since the radios require a decision between its options ... and so one is to be made in every case? otherwise we should use checkboxes ... i think?

kind regards
Jul 19 '07 #5
acoder
16,027 Expert Mod 8TB
so i think one radio-button should be checked initially ... since FF is not doing we have to specify it for ourselves ... in case i get what the spec says? ... i think this is to do, since the radios require a decision between its options ... and so one is to be made in every case? otherwise we should use checkboxes ... i think?

kind regards
Thanks for the clarification. You are right about the purpose of a radio button, but many times users don't bother setting default values for radio buttons.
Jul 19 '07 #6
gits
5,390 Expert Mod 4TB
;) yes ... in that case we should have a function that gets the initial checked-state of the radios at the onload of the body ... we store that state and on reset we restore it ...

and it seems that FF doesn't follow the specification in that case? it should initially check the first radio when the 'programer' didn't ... does other browsers do? ... i don't know because i generally try to avoid radios ... i don't find them very useful ... in most cases its better replaced with a dropdown-box

kind regards
Jul 19 '07 #7
davidj
6
Hi,

Tried this and it just resets to the first value.

How do you unset all the radio button choices.

Thanks
David J
Bytes Interactive
http://www.bytesinteractive.com
Aug 2 '07 #8
acoder
16,027 Expert Mod 8TB
Hi,

Tried this and it just resets to the first value.

How do you unset all the radio button choices.
David, welcome to TSDN!

Loop through the radio buttons and set the checked value to false:
Expand|Select|Wrap|Line Numbers
  1. for (i = 0; i < rgrp.length; i++) {
  2.   rgrp[i].checked = false;
  3. }
Don't forget though that radio buttons are supposed to have an initial state.
Aug 2 '07 #9
davidj
6
Thanks
That worked.

dj
Aug 2 '07 #10
acoder
16,027 Expert Mod 8TB
Thanks
That worked.

dj
You're welcome.
Aug 3 '07 #11

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

Similar topics

2
by: sramruttun | last post by:
hi I have a checkbox and a radiobuttonlist (the radiobuttonlist contains 2 items) in my form. The radiobuttonlist has its visible property set to false at design time. At run time, when the...
2
by: Sean | last post by:
Hi .... I have a radiobutton list and a label in a webform. <asp:radiobuttonlist id="one" runat="server" CssClass="text" AutoPostBack="False" RepeatDirection="Horizontal"> <asp:ListItem...
2
by: mg | last post by:
After a selection is made in the following RadioButtonList <asp:RadioButtonList id="RadioButtonList1" runat="server"> <asp:ListItem Value="Y"></asp:ListItem> <asp:ListItem...
5
by: DotNetGruven | last post by:
Anyone have any pointers on how to set the Value and Selected attributes in a ListItem in a RadioButtonList that is in a DataGrid? Here's what I have ------DataGrid------ -- BoundColumn 0 --...
6
by: DotNetGruven | last post by:
I have a webform that has a DataGrid on it with a RadioButtonList in each row. It is a simple On & Off. When the User Clicks on either of the RadioButtons, I need to postback to the server and...
0
by: Ryan Taylor | last post by:
Hello. I am having another issue. I need to execute some JavaScript whenever a radio button is clicked. I am currently using a RadioButtonList control to generate the radio buttons because of...
2
by: Alphonse Giambrone | last post by:
Hi all, I have two radiobuttonlist controls on a page. When a user checks 'No' for rblDeleted, I want to automatically set rblSendCard to 'No' and disable it. The javascript function I wrote to...
1
by: novice_developer | last post by:
Hi All, there is a radiobuttonlist having 2 list items (state & zipcode). when i select state radiobutton the zipcode textbox should be disabled and when i select a zipcode radiobutton the state...
1
by: jmgro | last post by:
I have spent way too much time trying to solve the following problem: I have a datalist with a timer in the footer template. It works wonderfully except when the user pages back, then forward,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.