IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New or currentStyle and GetComputedStyle
And then suddenly it's 3:30 in the morning and you can't let go of the problem and come up with this:
\n<html>\n\t<head>\n\t\t<title>Test</title></head><body>\n\t\t<form id='TestForm' name='TestForm'>\n\t\t\t<select id='TestList' name='TestList'>\n\t\t\t\t<option value='1'>Test Me #1</option>\n\t\t\t\t<option value='2'>Test Me #2 - a long one</option>\n\t\t\t</select>\n\t\t</form>\n\t</body>\n\t<script>\n\t\tfunction displayWidths(desc, tlst) {\n\t\t\tisIE = document.all;\n\t\t\tif(isIE) {\n\t\t\t\ttlst_cs_width = tlst.currentStyle.width;\n\t\t\n\t\t\t} else {\n\t\t\t\ttlst_comp_width = document.defaultView.getComputedStyle(tlst, '').getPropertyValue("width");\n\t\t\t}\n\t\t\t\n\t\t\tresults = desc + "\\n" +\n\t\t\t\t\t"clientWidth = " + tlst.clientWidth + "\\n" +\n\t\t\t\t\t"style.width = " + tlst.style.width + "\\n";\n\t\t\tif(isIE) {\n\t\t\t\tresults += "currentStyle.width = " + tlst_cs_width + "\\n"; \n\t\t\t} else {\n\t\t\t\tresults += "ComputedStyle Width = " + tlst_comp_width + "\\n";\n\t\t\t}\n\t\t\talert(results);\n\t\t\treturn;\n\t\t}\n\t\t\t\t\n\t\ttlst = document.getElementById("TestList");\n\t\tdisplayWidths("Before", tlst);\n    \t        tlst.style.width = 100;\n\t\tdisplayWidths("Set to 100", tlst);\n\t</script>\n</html>\n

Apparently currentStyle (IE) and getComputedStyle (DOM) are the way to get style info that wasn't set inline. I'm not sure why Moz returns a shorter value than IE.

--
Chris Altmann
New Thank ye kind sir
That one's been nagging on me. Appreciate the help!
     Finding the Select width from JavaScript - (ChrisR) - (3)
         Try clientWidth instead - (altmann) - (2)
             or currentStyle and GetComputedStyle - (altmann) - (1)
                 Thank ye kind sir - (ChrisR)

Just because your vocabulary is extremely limited doesn't mean the rest of the world can't use that word.
52 ms