Subject: IE not performing onFocus event for <select>
Posted By: kapstan Post Date: 1/24/2006 11:19:03 AM
Hi there,
I am having a problem with IE not allowing a CSS border to be drawn through javascript
in an onFocus event.

Here's an example:
<div class = "fieldname">Requester Name: <span style = "color:#FF0000"> *</span><br>
  <select class = "field"
          name = "Requester Info"
          id = "RequesterName"
          onFocus = document.getElementById('RequesterName').style.border = '2px solid #3EC4FE'"
          onBlur = "document.getElementById('RequesterName').style.border = '2px solid #CCCCCC'">
          <option value = "Select your name">Select your name</option>
  </select>
</div>

so basically when the select gains focus, a border is drawn around it to show the user where they are in the form.

This code works just fine on Gecko/Mozilla/KHTML but does not work in IE, cannot figure it out.  

Any help would be appreciated.

Thanks.
Reply By: richard.york Reply Date: 1/24/2006 11:30:22 AM
You're missing a double quote:

onFocus = "document.getElementById('RequesterName').style.border = '2px solid #3EC4FE'"

You can also do it this way and save space:

onFocus = "this.style.border = '2px solid #3EC4FE'"

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
Reply By: kapstan Reply Date: 1/24/2006 11:41:54 AM
Hey there,

Thank you for the response.  I tried what you pasted in, no-dice.

Are you able to replicate this error on your machine? If so, let me know cos i'm starting to think that there is something in a JavaScript include that is causing this.

Thanks for the help,
IK
Reply By: richard.york Reply Date: 1/24/2006 12:35:45 PM
Oops, well, according to these MSDN documents the <select> object does not support the border property.  Seemed like I used a border property on those before, but I guess I'm mistaken.

http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/select.asp
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/border_0.asp

The only way to work around that is to build your own <select> like object using JavaScript.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
Reply By: kapstan Reply Date: 1/24/2006 1:10:42 PM
thanks for the links.  i know for a fact that i have done that before using document.getElementById("").style.borderStyle, borderColor and borderWidth..

weirdness.  i appreciate your help.

Go to topic 39007

Return to index page 387
Return to index page 386
Return to index page 385
Return to index page 384
Return to index page 383
Return to index page 382
Return to index page 381
Return to index page 380
Return to index page 379
Return to index page 378