get value of dynamiclly created radiobuttonlist
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:
开发者_JAVA技巧 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
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.
精彩评论