开发者

Trying to select radio button based on asp variable

Hi and thanks for your help,

I am trying to select a radio button based on an ASP vari开发者_Python百科able. This variable directly correlates to the value field of the radio button.

Any ideas guys/gals?

Thanks, Will


var myradiogroup = document.getElementsByName('groupname of radio buttons');
                   // or document.forms['formname'].elements['radiogroupname'];
for (i=0; i<myradiogroup.length; i++){
     if (myradiogroup[i].value == '<%= myASPValue %>') myradiogroup[i].checked = true;
     else myradiogroup[i].checked = false;
}

remember, radio buttons come in groups... your question does not specify if you want that in server side or client side, i assumed its client side


You can do it in the ASP Server-Side code by checking if the value of the radio button is equal to your variable.

<input type="radio" ... value="<%=sRadioButtonValue%>" <% If sValue = sRadioButtonValue Then Response.Write "checked=""checked""" %> />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜