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

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

  1. rexall pharmacy amoxicillin 500mg IDARI amoxicillin azithromycin

  2. stromectol tablets uk Institute for Clinical Pharmacology & Safety ivermectin 2ml

  3. where can i buy amoxicillin without prec Amoxicillin amoxicillin 825 mg

  4. I’ve been browsing online more than 4 hours
    today, yet I never found any interesting article like yours.
    It’s pretty worth enough for me. In my opinion, if all site owners and bloggers made good content
    as you did, the web will be much more useful than ever before.

    my web site: polska ukraina wynik (https://basketball-wetten.com)

  5. amoxicillin 500mg cost amoxicillin 500mg price buy amoxicillin over the counter uk

  6. luckmore

    Когда искал luckmore casino зеркало, оказалось что проще всего пользоваться официальным telegram-каналом проекта. Там всегда есть актуальные ссылки и новые зеркала. Пока доступ работает стабильно

  7. luckmore casino

    Когда искал лакмор казино бонусы, заодно проверял и актуальные зеркала проекта. Этот telegram-канал оказался самым удобным источником. Все ссылки внутри рабочие и обновляются регулярно

  8. stromectol without prescription Clinical Pharmacology and Safety Profiles of Stromectol ivermectin buy

  9. лакмор казино официальный тг

    Когда искал рабочее зеркало Luckmore Casino, сначала попадались старые ссылки. Потом нашел их официальный telegram-канал и через него спокойно зашел без проблем. Сейчас использую именно этот вариант для входа. Все работает стабильно

  10. лакмор казино

    Когда понадобился лакмор казино вход после блокировки старого домена, проще всего оказалось зайти через telegram. Там сразу нашел актуальную ссылку и смог нормально авторизоваться. Сейчас пользуюсь именно этим способом

  11. ivermectin price comparison ivermectin oral 0 8 ivermectin tablets order

  12. лакмор казино бонусы

    Luckmore Casino сейчас выглядит намного интереснее многих старых проектов. Проверял бонусы, регистрацию и несколько слотов — все открывается быстро. Через telegram-канал удобно следить за новыми зеркалами и актуальными ссылками

  13. luckmore

    Недавно увидел Luckmore Casino в подборке новых проектов и решил протестировать. Сайт оказался полностью рабочим, а telegram-канал реально помогает быстро находить актуальные зеркала. Пока все работает отлично

  14. canadian pharmacy amoxicillin AmoxilIdari amoxicillin 500 mg tablets

  15. stromectol for humans Ivermectin ivermectin buy australia

  16. buy amoxicillin online uk Amoxicillin medicine amoxicillin 500

  17. Online medicine home delivery: world pharmacy india – buy online medicine

  18. mail order pharmacy mexico mexican pharmacy menu MexiCare Direct

  19. Easy North RX: buying from canadian pharmacies – Easy North RX

  20. Заказать печать на ПВД пакетах с логотипом в России Заказать печать на ПВД пакетах с логотипом в Санкт-Петербурге

  21. los algodones pharmacy online: MexiCare Direct – online pharmacy

  22. отзывы на авито накрутка Заказать накрутку отзывов для Профи ру. Купить отзывы с гарантией. Прямой контакт с исполнителем Без посредников. Лучшая цена и условия Репутационное агентство РА OTZA

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>