Click here to Skip to main content
13,350,289 members (46,222 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 31 May 2011

JavaScript RadioButtonList get and set values

, 31 May 2011
Rate this:
Please Sign up or sign in to vote.
Getting and Setting RadioButtonLists in JavaScript for ASP.NET
I am by no means a JavaScript expert, but had to get my feet wet as I couldn't find a working piece of code that allowed an update of radio button list via JavaScript.
There are two JavaScript Functions: getRadVal will get the value of a RadioButtonList and setRadVal will set the value of value of a RadioButtonList.

function getRadVal(radlist)
 if (document.forms['Form1'].elements[radlist])
 {  var radGrp = document.forms['Form1'].elements[radlist];
  var radGrpValue = '0';
  for (var i = 0; i < radGrp.length; i++) 
      if (radGrp[i].checked) {
          radGrpValue = radGrp[i].value;
  return radGrpValue;
  return '';
function setRadVal(radlist, newValue) {
    if (document.forms['Form1'].elements[radlist]) {
        var radGrp = document.forms['Form1'].elements[radlist];
        for (var i = 0; i < radGrp.length; i++) {
            radGrp[i].Checked = false;
            var evalue = radGrp[i].value         
            if (evalue == newValue) {
                radGrp[i].checked = true;
                radGrp[i].value = newValue;               

These are called as:

// Get Value of RadioButtonList
var myValue=getRadVal('UCMAIN:RadioList1')
//Set Value of RadioButtonList
setRadVal('UCMAIN:RadioList2', myValue)

The above example syncs two RadioButtonLists with the same value.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Frank Kerrigan
Software Developer (Senior)
United Kingdom United Kingdom
Frank Kerrigan

Currently developing Insurance systems with SQL Server, ASP.NET, C#, ADO for a company in Glasgow Scotland. Very keen on OOP and NUNIT testing. Been in IT forever (20 years) in mix of development and supporting applications / servers. Worked for companies big and small and enjoyed both.

Developed in (newest first) : C#, Progress 4GL, ASP.NET, SQL TSQL, HTML, VB.NET, ASP, VB, VBscript, JavaScript, Oracle PSQL, perl, Access v1-2000, sybase/informi, Pic Controllers, 6502 (ask your dad).

Msc .Net Development Evenings
MCAD Passed
MCP C# ASP.NET Web Applications
MCP SQL Server 2000
HND Computing
OND / HNC Electrical Engineering,

You may also be interested in...

Comments and Discussions

GeneralReason for my vote of 5 nice work Pin
Monjurul Habib9-Jun-11 12:00
memberMonjurul Habib9-Jun-11 12:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 31 May 2011
Article Copyright 2011 by Frank Kerrigan
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid