views:

37

answers:

1

Hi All,

I'm trying to get the value of a dynamically created radiobuttonlist via javascript to call a pagemethod.

This is how I'm creating the rbl:

rbl.Attributes["onclick"] = "javascript:preview('" + rbl.ID + "','" + rbl.ClientID + "');";

And this is the javascript:

        function preview(controlid, clientid)
    {
        var radio = document.getElementsByName(clientid);
        var answer = "k";
        for (var ii = 0; ii < radio.length; ii++)
        {
            if (radio[ii].checked)
                answer = radio[ii].value;
        }

         PageMethods.SaveAnswer(controlid, answer);

    }

The problem however is that I want to get the groupname of the radiobuttionlist so I can use getElementsByName, but i have no luck so far.

Kind regards, Mark

A: 

Ah well I got a temporary solution for now just to continue..

    <script type="text/javascript" language="javascript">
    function SaveAnswer(ctrlid)
    {
        var answer;
        var radio = document.getElementsByName('ctl00$cphContent$' + ctrlid);

        for (var ii = 0; ii < radio.length; ii++)
        {
            if (radio[ii].checked)
                answer = radio[ii].value;
        }

         PageMethods.SaveAnswer(ctrlid, answer);

    }
    function onComplete(res)
    {
        //alert(res);
    }
</script>

As you can see i added ctrl00$cphContent$ by hand.

Kind regards, Mark

Mark