Topic
2 replies Latest Post - ‏2012-11-16T13:36:07Z by kachi
MadhuAnne
MadhuAnne
5 Posts
ACCEPTED ANSWER

Pinned topic Issue while fetching the selected radio button value in java script

‏2012-09-04T14:20:04Z |
Hi,

I created RadioButtons by using RadioButton Group builder with help of RichDataDefination.
Now i am trying to get the selected value of Radio button in the Javascript function. I am trying with following code
document.getElementById("xxxxx").value;

But unable to get value.
Any one Please suggest me on this. It's urgent.. Please reply ASAP.

Thanks&Regards,
MadhUAnne.
Updated on 2012-11-16T13:36:07Z at 2012-11-16T13:36:07Z by kachi
  • Dinger
    Dinger
    91 Posts
    ACCEPTED ANSWER

    Re: Issue while fetching the selected radio button value in java script

    ‏2012-09-04T15:27:53Z  in response to MadhuAnne
    Hi MudhuAnne,

    I think you've already solved this, but I'll post the solution we discussed. It allows you to get the selected radio value using only the name of the RadioGroup (which you know). You don't have to know the (generated) IDs of the radio buttons.


    function getRadioGroupValue(radioGroupName)
    {
    var retVal = null;
    var radios = document.getElementsByName(radioGroupName);

    if (radios && radios.length > 0)
    {
    for (var i = 0; i < radios.length; i++)
    {
    if (radios[i].type == 'radio' && radios[i].selected)
    {
    retVal = radios[i].value;
    break;
    }
    }
    }

    return retVal;
    }


  • kachi
    kachi
    9 Posts
    ACCEPTED ANSWER

    Re: Issue while fetching the selected radio button value in java script

    ‏2012-11-16T13:36:07Z  in response to MadhuAnne
    Hi MudhuAnne,

    Small correction for mentioned code as I have tested mentioned code it is not working,radios[i].checked
    is working fine.