jQuery plugin to associate label “for” attribute with form controls that have dynamic id’s

For whatever reason, you can’t associate your labels with your form controls implicitly by wrapping both the label text and the control in a <label> element:

<label>
  Email address: <input type="email" name="email" value="" placeholder="you@example.com"/>
</label>

You’ve had to explicitly state the form control you want the label to be associated with:

<label for="email">Email address:</label>
<input id="email" type="email" name="email" value="" placeholder="you@example.com"/>

…but your framework has other ideas, it decides to commandeer your precious “id” attribute and change it from a simple and beautiful “email” into a junky “dnn_ctr1163_RegistrationForm_email”. *cough* DotNetNuke *cough*, but also *cough* Wicket *cough* and probably a whole load of others.

The problem is now that your label is no longer associated with your form control, and there isn’t a simple fix, like, for example, change the for attribute to read “dnn_ctr1163_RegistrationForm_email”, because the numbers in the id change each time you refresh the page. The ID is dynamic, and you are receiving accessibility black stars.

So, luckily I noticed that often the id will change, but the framework will leave your originally intended id somewhere in there. I’ve written a jQuery plugin to look at label for attributes and try to find the form control you intended to associate it with before your server side framework so rudely changed it.

How to use

  1. Download the plugin and add it to your page
  2. Select the labels you want to re-associate and call the function eg. $(‘label’).fuzzyFor();

TODO

The plugin finds matches by looking for input, select and textarea elements in the document and checking to see if the for attribute in your label element appears in the id attribute of the form control. At the moment if more than one match is found, it just uses the first (which is probably good enough for most). However, it should probably do something a bit more clever and use the form control that is closest to the label (I’m reasoning that you normally put your label’s close to your controls).

1,618 thoughts on “jQuery plugin to associate label “for” attribute with form controls that have dynamic id’s

  1. п»їRecently I came across an informative guide about ordering meds from India. The site discusses WHO-GMP protocols on prescriptions. If you are looking for cheaper alternatives take a look: п»їkisawyer.us.com. Good info.

  2. For those looking to save money on prescriptions you should try visiting this page. It reveals prices for generics. Huge savings found here: п»їhttps://polkcity.us.com/# buying prescriptions in mexico.

  3. п»їLately I discovered a great page concerning buying affordable antibiotics. It explains how to save money on prescriptions. If you are looking for cheaper alternatives read this: п»їkisawyer.us.com. It helped me.

  4. п»їTo be honest I discovered a great guide regarding cheap Indian generics. It covers the manufacturing standards on prescriptions. If you are looking for reliable shipping to USA visit this link: п»їhttps://kisawyer.us.com/# india online pharmacy. Good info.

  5. Sharing a detailed article on buying meds safely. The author describes quality control for antibiotics. Full info: п»їmore info.

  6. п»їLately I came across a useful page concerning safe pharmacy shipping. The site discusses how to save money for generic meds. For those interested in reliable shipping to USA go here: п»їhttps://polkcity.us.com/# mexico rx. Hope it helps.

  7. п»їActually I discovered an interesting article about Indian Pharmacy exports. It explains how to save money for generic meds. For those interested in Trusted Indian sources take a look: п»їworld pharmacy india. Might be useful.

  8. п»їTo be honest I discovered a helpful guide concerning Indian Pharmacy exports. It covers the manufacturing standards when buying antibiotics. For those interested in Trusted Indian sources read this: п»їkisawyer.us.com. Hope it helps.

  9. п»їLately I stumbled upon a helpful report concerning Mexican Pharmacy standards. The site discusses how to save money for ED medication. If you are looking for reliable shipping to USA go here: п»їpharmacies in mexico. It helped me.

  10. п»їActually I came across an informative report concerning cheap Indian generics. It explains CDSCO regulations when buying antibiotics. In case you need cheaper alternatives visit this link: п»їkisawyer.us.com. Good info.

  11. п»їTo be honest I found a useful page about ordering meds from India. It explains how to save money when buying antibiotics. For those interested in Trusted Indian sources go here: п»їkisawyer.us.com. It helped me.

  12. Stop overpaying and save big on pills you should try visiting this page. It reveals shipping costs. Best prices available here: п»їUpstate Medical.

  13. Heads up a detailed analysis on cross-border shipping rules. It breaks down the best shipping methods for generics. You can read it here: п»їUpstate Medical.

  14. п»їActually I found a useful resource about generic pills from India. The site discusses the manufacturing standards for generic meds. If anyone wants factory prices visit this link: п»їhttps://kisawyer.us.com/# best india pharmacy. Might be useful.

  15. п»їRecently I stumbled upon an informative guide concerning buying affordable antibiotics. The site discusses the manufacturing standards on prescriptions. In case you need reliable shipping to USA read this: п»їhttps://kisawyer.us.com/# india pharmacy mail order. Hope it helps.

  16. Quick question about getting antibiotics without prescription. I saw a decent archive that lists affordable options: п»їhttps://polkcity.us.com/# mexico rx. Seems useful..

  17. п»їActually I discovered a helpful article concerning ordering meds from India. It explains CDSCO regulations for ED medication. For those interested in cheaper alternatives take a look: п»їkisawyer.us.com. Might be useful.

  18. п»їRecently I discovered a useful report about cheap Indian generics. It details how to save money for ED medication. If anyone wants factory prices go here: п»їhttps://kisawyer.us.com/# Online medicine order. Might be useful.

  19. If you want to save cash on meds you should try checking this resource. It shows prices for generics. Discounted options at this link: п»їpurple pharmacy online.

  20. п»їLately I discovered an informative article about ordering meds from India. It details WHO-GMP protocols for generic meds. In case you need Trusted Indian sources take a look: п»їkisawyer.us.com. It helped me.

  21. п»їRecently I discovered a helpful article concerning Indian Pharmacy exports. It covers how to save money for ED medication. If you are looking for cheaper alternatives take a look: п»їtop 10 online pharmacy in india. Worth a read.

  22. I was wondering about ordering meds from Mexico. I found a good archive that lists trusted vendors: п»їhttps://polkcity.us.com/# medicine mexico. Any thoughts?.

  23. п»їJust now I stumbled upon a great guide about cheap Indian generics. It explains CDSCO regulations for generic meds. If anyone wants reliable shipping to USA check this out: п»їhttps://kisawyer.us.com/# mail order pharmacy india. Cheers.

  24. п»їRecently I came across an informative guide about ordering meds from India. It covers how to save money when buying antibiotics. For those interested in factory prices take a look: п»їbuy medicines online in india. Might be useful.

  25. п»їRecently I stumbled upon an informative report regarding Indian Pharmacy exports. It details WHO-GMP protocols on prescriptions. If anyone wants cheaper alternatives take a look: п»їhttps://kisawyer.us.com/# reputable indian pharmacies. It helped me.

  26. п»їJust now I discovered an interesting resource regarding generic pills from India. It explains WHO-GMP protocols when buying antibiotics. In case you need reliable shipping to USA go here: п»їindia pharmacy. Cheers.

  27. Does anyone know safe Mexican pharmacies. I saw a verified blog that ranks safe places: п»їpolkcity.us.com. Any thoughts?.

  28. п»їTo be honest I came across an informative article concerning Indian Pharmacy exports. It covers CDSCO regulations for ED medication. If you are looking for Trusted Indian sources go here: п»їhttps://kisawyer.us.com/# top 10 pharmacies in india. Cheers.

  29. п»їLately I stumbled upon a useful report concerning cheap Indian generics. It covers the manufacturing standards on prescriptions. If you are looking for Trusted Indian sources read this: п»їhttps://kisawyer.us.com/# india pharmacy mail order. Hope it helps.

  30. стайлер дайсон для волос с насадками купить официальный сайт цен… стайлер дайсон для волос с насадками купить официальный сайт цен… .

  31. стайлер дайсон для волос с насадками купить официальный сайт цен… стайлер дайсон для волос с насадками купить официальный сайт цен… .

  32. стайлер для волос дайсон цена с насадками официальный сайт купит… стайлер для волос дайсон цена с насадками официальный сайт купит… .

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>