Script to enable combo box on selecting radio button

andyh20

Member
Joined
Aug 4, 2009
Messages
11
Programming Experience
5-10
Help,

How do I enable an ASP combo box when a user clicks the radio button alongside it. I've tried:

rdoSpec.Attributes.Add("onclick", String.Format("document.getElementById(cboSpec).disabled=!this.checked;", rdoSpec.ClientID))

in my page load but no joy.

It's complicated by the fact that I've actually got three options with a combo alongside each one and only want the combo alongside the selected radio to be selected. I figured one step at a time and that if I could get manage the above, I'll take the disabling from there.

Cheers,
Andy
 
I havent really worked much with enabling/disabling controls through javascript, I've always done it through postbacks, but a couple of things caught my eye.

First, you have a space in the middle of 'disabled' don't know if that was copied and pasted...

Second, i think
VB.NET:
rdoSpec.Attributes.Add("onclick", String.Format("document.getElementById(cboSpec).di sabled=!this.checked;", rdoSpec.ClientID))

needs to be more like this
VB.NET:
"rdoSpec.Attributes.Add("onclick", String.Format("document.getElementById({0}).disabled=!this.checked;", rdoSpec.ClientID))
 
Thanks

Thanks,

That pointed me in the right direction. The working code was:

rdoSpec.Attributes.Add("onclick", String.Format("document.getElementById({0}).disabled=!this.checked;", cboSpec.ClientID))

The trick was that {0}.

Cheers,
Andy
 
Back
Top