Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use onFocus with .Net RadioButtons? 1

Status
Not open for further replies.

colin5

Programmer
Jul 1, 2002
3
US
Anyone worked out how to use the onFocus Attribute on the .Net RadioButton ?

In your code behind, if you do:

RB1.Attributes("onFocus") = "javascript:alert()"

the rendered html is:

<span onFocus=&quot;javascript:alert()&quot; style=&quot;height:52px;width:132px;Z-INDEX: 101; LEFT: 367px; POSITION: absolute; TOP: 227px&quot;><input id=&quot;RB1&quot; type=&quot;radio&quot; name=&quot;RB1&quot; value=&quot;RB1&quot; /></span>

..but the javascript does not run.


Note however that onClick does work...

RB1.Attributes(&quot;onClick&quot;) = &quot;javascript:alert()&quot;

gives..

<span onClick=&quot;javascript:alert()&quot; style=&quot;height:52px;width:132px;Z-INDEX: 101; LEFT: 367px; POSITION: absolute; TOP: 227px&quot;><input id=&quot;RB1&quot; type=&quot;radio&quot; name=&quot;RB1&quot; value=&quot;RB1&quot; /></span>


The javascript works fine. The only difference is that this is now an onClick and not an onFocus. If anyone can shed any light on this, or even tell me a way to use onClick that will work correctly when I tab into it (ie same functionality as onFocus), I would be really greatful.

Colin




 
try the .add method of the attributes collection:

RB1.Attributes.Add(&quot;onFocus&quot;,&quot;alert();&quot;)

hth :)
paul
penny1.gif
penny1.gif
 
Thanks for the help paul - but I couldn't get this to work on my system. The syntax you suggest,

Code:
RB1.Attributes.Add(&quot;onFocus&quot;, &quot;alert();&quot;)

works fine for onClick, but I get the same 'none result' for onFocus.

Does onFocus work on your system?

colin [roll1]
 
Hey Collin,

Just throwing this out: in school I remember they talked about an &quot;onBlur&quot; attribute with javascript, and it had something to do with tabbing or focusing or something (heh, it was a while ago).

Maybe instead of onFocus try onBlur and see if that works?

Jack
 
Thanks Jack,

- my experience with onBlur is that it doesn't work in Netscape too well, but I'll play around and let you all know what I find.

-- Any other ideas on how to get onFocus to work with the dot Net radio Button would be great greatly appreciated.

I'm also open to any work around (such as onClick if I could come up with a good keyboard alternative too). Note that the problem seems to be only with the dot Net Radio Button. I think the onFocus on the radio button works ok.

Colin
ps I am using IE6.0 primarily, but have to work back to 4.0


colin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top