Will Howard
Will Howard

Reputation: 51

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 variable. This variable directly correlates to the value field of the radio button.

Any ideas guys/gals?

Thanks, Will

Upvotes: 0

Views: 2128

Answers (2)

Shawn Steward
Shawn Steward

Reputation: 6825

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""" %> />

Upvotes: 1

Ayyash
Ayyash

Reputation: 4399

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

Upvotes: 1

Related Questions