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).

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

  1. Hello mọi người người anh em nào cần sân chơi đẳng cấp để cày cuốc Game bài thì vào ngay trang này nhé. Uy tín luôn: https://homemaker.org.in/#. Chúc các bác rực rỡ.

  2. Chào anh em người anh em nào cần cổng game không bị chặn để gỡ gạc Game bài thì xem thử địa chỉ này. Nạp rút 1-1: https://pacebhadrak.org.in/#. Húp lộc đầy nhà.

  3. Chào cả nhà ai đang tìm cổng game không bị chặn để gỡ gạc Game bài đừng bỏ qua trang này nhé. Nạp rút 1-1: sunwin. Về bờ thành công.

  4. united statesn roulette wheel play, best online pokies in canada and canadian pokies winners, or australia online
    gambling stock

    Feel free to visit my blog post; cherokee casino nc open (Ralf)

  5. paypal gambling sites canada, us casinos taking canada
    money and ontario australia online gambling, or no wagering casino
    uk

    Look into my web page – wizard of odds blackjack side bets – Miles -

  6. iphone не включается ремонт великий новгород срочно ремонт айфон недорого в великом новгороде цена

  7. Hello mọi người nếu anh em đang kiếm sân chơi đẳng cấp để giải trí Nổ Hũ thì vào ngay con hàng này. Nạp rút 1-1: https://homemaker.org.in/#. Chúc anh em may mắn.

  8. Ставки баскетбол Прогнозы на хоккей – это попытка заглянуть в будущее ледовой баталии. Это анализ статистики учет травм и дисквалификаций оценка мотивации команд и многое другое. Помните что прогноз – это не гарантия а лишь вероятность.

  9. Hi cac bac n?u anh em dang ki?m c?ng game khong b? ch?n d? choi Game bai d?ng b? qua d?a ch? nay. Uy tin luon: Link khong b? ch?n. Chuc cac bac r?c r?.

  10. Лучшее казино ап икс играйте в слоты и live-казино без лишних сложностей. Простой вход удобный интерфейс стабильная платформа и широкий выбор игр для отдыха и развлечения.

  11. Играешь в казино? ап икс официальный Слоты рулетка покер и live-дилеры простой интерфейс стабильная работа сайта и возможность играть онлайн без сложных настроек.

  12. Играешь в казино? t.me Слоты рулетка покер и live-дилеры простой интерфейс стабильная работа сайта и возможность играть онлайн без сложных настроек.

  13. Нью клининг Клиндо – это синоним качества и надежности в мире клининга.

  14. Лучшее казино up x играйте в слоты и live-казино без лишних сложностей. Простой вход удобный интерфейс стабильная платформа и широкий выбор игр для отдыха и развлечения.

  15. Hi cac bac n?u anh em dang ki?m trang choi xanh chin d? gi?i tri Game bai d?ng b? qua ch? nay. Uy tin luon: Link t?i Sunwin. V? b? thanh cong.

  16. самые красивые пляжи краби в тайланде golden beach resort краби

  17. Hello m?i ngu?i n?u anh em dang ki?m trang choi xanh chin d? cay cu?c Da Ga thi xem th? trang nay nhe. T?c d? ban th?: Link t?i Sunwin. Chi?n th?ng nhe.

  18. Хоккей кхл Хоккей КХЛ – это российская лига объединяющая лучшие клубы страны и ближнего зарубежья.

  19. Лучшее казино https://t.me/ играйте в слоты и live-казино без лишних сложностей. Простой вход удобный интерфейс стабильная платформа и широкий выбор игр для отдыха и развлечения.

  20. ivermectin purchase: stromectol pills – Iver Protocols Guide

  21. Avia Masters de BGaming es un juego crash con RTP del 97 donde apuestas desde 010€ hasta 1.000€ controlas la velocidad de vuelo de un avion que recoge multiplicadores hasta x250 mientras evita cohetes que reducen ganancias a la mitad con el objetivo de aterrizar exitosamente en un portaaviones para cobrar el premio acumulado https://feg.org.es/

  22. Iver Protocols Guide: stromectol 3 mg price – generic ivermectin

  23. AmiTrip Relief Store: Elavil – AmiTrip Relief Store

  24. Follicle Insight: Follicle Insight – buying generic propecia without dr prescription

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>