Confessions of a Social Tools Architect
11 Jan
I’ve been working quite a bit on a variety of interface modules this week already and they’re coming along quite nice (in Firefox). You see, the problem is that, IMNSHO, Safari and IE are equally useless :)
Truth be told, I’m sooo tired of going round in circles testing one thing here, testing another thing there, and then going back and fixing what just got broken. It’s like sleeping on an ice cold night with a blanket that’s just too small to cover you up all the way. Tug it a little in one direction, your toes are frozen. Tug it in the other direction and your nose is getting frostbitten.
Today I had another one of those wonderful episodes where I was indeed tugging. The culprit - the label tag. I have been working on a widget for our tagging needs in the system (see screenshot) and I had it working great in Firefox but no dice in IE and Safari. Why? Look at this code:

<label class="check" onclick="toggleCheck(this)"><input type="checkbox" /></label>
Looks simple enough. Now, note that the <input> is inside the label which should rightly NOT require that I specify who it’s for. Works fine in Firefox. So I then made my effort to complete the regular setup for the <label>:
<label class="check" onclick="toggleCheck(this)" for="id"><input type="checkbox" id="id" /></label>
So, with this, I had IE working and not the Firefox. Why? Well IE will let you put an onclick on pretty much anything. So this was working just fine. Problem was that Firefox won’t honor a click on a label since it forwards the click on to the input that it’s targeting (seems reasonable). So here comes one of the stupidest hacks I can think of:
<label class="check" onclick="toggleCheck(this)" for="id"><input type="checkbox" id="id" onclick="toggleCheck(this.parentNode)" /></label>
Yup. I’m calling the function in BOTH places. Why? Well, the problem with IE is that if the checkbox is hidden, it won’t accept the forwarded click. So, in IE, the onclick on the <label> is doing the work and in Firefox the one on the <input> is doing the work. I don’t know which case is true for Safari.
Moral of the story. Don’t let anyone tell you doing things the right way is ever easy ;) All the more reason to sympathize with us hard-working entrepreneurs that have limited resources and are trying to build things that work well for everyone.
3 Responses for "Developer Notes: <label>"
http://busca.wanadoo.es/search?buscar=mundo-descargas.com
http://onlypitch.com/pitus1/ MdRH1 http://onlypitch.com/pitus10/ MdRH2 http://onlypitch.com/pitus100/ MdRH3 http://onlypitch.com/pitus101/ MdRH4 http://onlypitch.com/pitus102/ MdRH5 http://onlypitch.com/pitus103/ MdRH6 http://onlypitch.com/pitus104/ MdRH7 http://onlypitch.com/pitus105/ MdRH8 http://onlypitch.com/pitus106/ MdRH9 http://onlypitch.com/pitus107/ MdRH10 http://onlypitch.com/pitus108/ MdRH11 http://onlypitch.com/pitus109/ MdRH12 http://onlypitch.com/pitus11/ MdRH13 http://onlypitch.com/pitus110/ MdRH14 http://onlypitch.com/pitus111/ MdRH15 http://onlypitch.com/pitus113/ MdRH17 http://onlypitch.com/pitus114/ MdRH18 http://onlypitch.com/pitus115/ MdRH19 http://onlypitch.com/pitus116/ MdRH20 http://onlypitch.com/pitus117/ MdRH21 http://onlypitch.com/pitus118/ MdRH22 http://onlypitch.com/pitus119/ MdRH23 http://onlypitch.com/pitus12/ MdRH24 http://onlypitch.com/pitus120/ MdRH25 http://onlypitch.com/pitus121/ MdRH26 http://onlypitch.com/pitus122/ MdRH27 http://onlypitch.com/pitus123/ MdRH28 http://onlypitch.com/pitus124/ MdRH29 http://onlypitch.com/pitus125/ MdRH30 http://onlypitch.com/pitus126/ MdRH31 http://onlypitch.com/pitus127/ MdRH32 http://onlypitch.com/pitus128/ MdRH33 http://onlypitch.com/pitus129/ MdRH34 http://onlypitch.com/pitus13/ MdRH35 http://onlypitch.com/pitus130/ MdRH36 http://onlypitch.com/pitus131/ MdRH37 http://onlypitch.com/pitus132/ MdRH38 http://onlypitch.com/pitus133/ MdRH39 http://onlypitch.com/pitus134/ MdRH40 http://onlypitch.com/pitus135/ MdRH41 http://onlypitch.com/pitus136/ MdRH42 http://onlypitch.com/pitus137/ MdRH43 http://onlypitch.com/pitus138/ MdRH44 http://onlypitch.com/pitus139/ MdRH45 http://onlypitch.com/pitus14/ MdRH46 http://onlypitch.com/pitus140/ MdRH47 http://onlypitch.com/pitus141/ MdRH48 http://onlypitch.com/pitus142/ MdRH49 http://onlypitch.com/pitus143/ MdRH50 http://onlypitch.com/pitus144/ MdRH51 http://onlypitch.com/pitus145/ MdRH52 http://onlypitch.com/pitus146/ MdRH53 http://onlypitch.com/pitus147/ MdRH54 http://onlypitch.com/pitus148/ MdRH55 http://onlypitch.com/pitus149/ MdRH56 http://onlypitch.com/pitus15/ MdRH57 http://onlypitch.com/pitus150/ MdRH58 http://onlypitch.com/pitus151/ MdRH59 http://onlypitch.com/pitus152/ MdRH60 http://onlypitch.com/pitus153/ MdRH61 http://onlypitch.com/pitus154/ MdRH62 http://onlypitch.com/pitus155/ MdRH63 http://onlypitch.com/pitus156/ MdRH64 http://onlypitch.com/pitus157/ MdRH65 http://onlypitch.com/pitus158/ MdRH66 http://onlypitch.com/pitus159/ MdRH67 http://onlypitch.com/pitus16/ MdRH68 http://onlypitch.com/pitus160/ MdRH69 http://onlypitch.com/pitus161/ MdRH70 http://onlypitch.com/pitus162/ MdRH71 http://onlypitch.com/pitus163/ MdRH72 http://onlypitch.com/pitus164/ MdRH73 http://onlypitch.com/pitus17/ MdRH74 http://onlypitch.com/pitus18/ MdRH75 http://onlypitch.com/pitus19/ MdRH76 http://onlypitch.com/pitus2/ MdRH77 http://onlypitch.com/pitus22/ MdRH78 http://onlypitch.com/pitus23/ MdRH79 http://onlypitch.com/pitus24/ MdRH80 http://onlypitch.com/pitus25/ MdRH81 http://onlypitch.com/pitus26/ MdRH82 http://onlypitch.com/pitus27/ MdRH83 http://onlypitch.com/pitus28/ MdRH84 http://onlypitch.com/pitus29/ MdRH85 http://onlypitch.com/pitus3/ MdRH86 http://onlypitch.com/pitus30/ MdRH87 http://onlypitch.com/pitus31/ MdRH88 http://onlypitch.com/pitus32/ MdRH89 http://onlypitch.com/pitus33/ MdRH90 http://onlypitch.com/pitus34/ MdRH91 http://onlypitch.com/pitus35/ MdRH92 http://onlypitch.com/pitus36/ MdRH93 http://onlypitch.com/pitus37/ MdRH94 http://onlypitch.com/pitus38/ MdRH95 http://onlypitch.com/pitus39/ MdRH96 http://onlypitch.com/pitus4/ MdRH97 http://onlypitch.com/pitus40/ MdRH98 http://onlypitch.com/pitus41/ MdRH99 http://onlypitch.com/pitus42/ MdRH100 http://onlypitch.com/pitus43/ MdRH101 http://onlypitch.com/pitus44/ MdRH102 http://onlypitch.com/pitus45/ MdRH103 http://onlypitch.com/pitus46/ MdRH104 http://onlypitch.com/pitus47/ MdRH105 http://onlypitch.com/pitus48/ MdRH106 http://onlypitch.com/pitus49/ MdRH107 http://onlypitch.com/pitus5/ MdRH108 http://onlypitch.com/pitus50/ MdRH109 http://onlypitch.com/pitus51/ MdRH110 http://onlypitch.com/pitus52/ MdRH111 http://onlypitch.com/pitus53/ MdRH112 http://onlypitch.com/pitus54/ MdRH113 http://onlypitch.com/pitus55/ MdRH114 http://onlypitch.com/pitus56/ MdRH115 http://onlypitch.com/pitus57/ MdRH116 http://onlypitch.com/pitus58/ MdRH117 http://onlypitch.com/pitus59/ MdRH118 http://onlypitch.com/pitus6/ MdRH119 http://onlypitch.com/pitus60/ MdRH120 http://onlypitch.com/pitus61/ MdRH121 http://onlypitch.com/pitus62/ MdRH122 http://onlypitch.com/pitus63/ MdRH123 http://onlypitch.com/pitus64/ MdRH124 http://onlypitch.com/pitus65/ MdRH125 http://onlypitch.com/pitus66/ MdRH126 http://onlypitch.com/pitus67/ MdRH127 http://onlypitch.com/pitus68/ MdRH128 http://onlypitch.com/pitus69/ MdRH129 http://onlypitch.com/pitus7/ MdRH130 http://onlypitch.com/pitus70/ MdRH131 http://onlypitch.com/pitus71/ MdRH132 http://onlypitch.com/pitus72/ MdRH133 http://onlypitch.com/pitus73/ MdRH134 http://onlypitch.com/pitus74/ MdRH135 http://onlypitch.com/pitus75/ MdRH136 http://onlypitch.com/pitus76/ MdRH137 http://onlypitch.com/pitus77/ MdRH138 http://onlypitch.com/pitus78/ MdRH139 http://onlypitch.com/pitus79/ MdRH140 http://onlypitch.com/pitus8/ MdRH141 http://onlypitch.com/pitus80/ MdRH142 http://onlypitch.com/pitus81/ MdRH143 http://onlypitch.com/pitus82/ MdRH144 http://onlypitch.com/pitus83/ MdRH145 http://onlypitch.com/pitus84/ MdRH146 http://onlypitch.com/pitus85/ MdRH147 http://onlypitch.com/pitus86/ MdRH148 http://onlypitch.com/pitus87/ MdRH149 http://onlypitch.com/pitus88/ MdRH150 http://onlypitch.com/pitus89/ MdRH151 http://onlypitch.com/pitus9/ MdRH152 http://onlypitch.com/pitus90/ MdRH153 http://onlypitch.com/pitus91/ MdRH154 http://onlypitch.com/pitus92/ MdRH155 http://onlypitch.com/pitus93/ MdRH156 http://onlypitch.com/pitus94/ MdRH157 http://onlypitch.com/pitus95/ MdRH158 http://onlypitch.com/pitus96/ MdRH159 http://onlypitch.com/pitus97/ MdRH160 http://onlypitch.com/pitus98/ MdRH161 http://onlypitch.com/pitus99/ MdRH162
Greg, do you want Firefox to “honor” the click on the input? If you’re just keeping track in javascript anyway, couldn’t you just add
onclick=”toggleCheck(this); return false;”
to the label tag thus negating the need for the duplication on the input?
As for Safari, it doesn’t yet support “normal” clicking on the label tag whereby it toggles or focuses whichever form element it’s tied to BUT the onclick does fire on the label tag (just tested it using an alert).
Leave a reply