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,535 thoughts on “jQuery plugin to associate label “for” attribute with form controls that have dynamic id’s

  1. ivermectin 3 mg tabs: ivermectin where to buy for humans – Ivermectin First

  2. stromectol ivermectin buy: Ivermectin First – ivermectin 90 mg

  3. top online pharmacy: no prescription needed pharmacy – online drugs order

  4. ботинки рабочие без подноска с антискользящей подошвой Благодаря разнообразию моделей от бюджетных вариантов до более дорогих но не менее качественных каждый сможет купить рабочие ботинки без подноска отвечающие всем его ожиданиям и потребностям.

  5. техосмотр онлайн Прохождение техосмотра автомобиля в Санкт-Петербурге – это важный этап для каждого автовладельца гарантирующий безопасность на дороге и соответствие транспортного средства всем необходимым стандартам

  6. Thanks a lot for sharing this with all of us you really know what youre talking approximately Bookmarked. Kindly additionally talk over with my web site =). We will have a hyperlink trade contract among us free spins no deposit

  7. трансы самара Такая же потребность ощущается и в Омске и в Самаре где жители ищут единомышленников способных понять их принять и разделить их взгляды на жизнь.

  8. no prescription needed pharmacy: legitimate online pharmacy – legal online pharmacy

  9. Howdy I am so glad I found your web site I really found you by accident while I was looking on Digg for something else Regardless I am here now and would just like to say cheers for a incredible post and a all round exciting blog I also love the theme/design I dont have time to read through it all at the moment but I have bookmarked it and also included your RSS feeds so when I have time I will be back to read much more Please do keep up the great job. no deposit bonus

  10. I believe what you composed made a lot of sense. But what about this? what if you were to write a awesome title? I am not suggesting your information isnt solid. however suppose you added something that grabbed a persons attention? I mean BLOG_TITLE is a little plain. You could look at Yahoos front page and note how they create article headlines to grab viewers to open the links. You might add a video or a related pic or two to get readers excited about everythingve written. Just my opinion it would bring your website a little livelier. free spins no deposit

  11. Very good site you have here but I was curious if you knew of any forums that cover the same topics talked about here? Id really love to be a part of group where I can get responses from other experienced people that share the same interest. If you have any suggestions please let me know. Thanks a lot free spins no deposit

  12. This web site really has all of the info I wanted about this subject and didnt know who to ask. no deposit bonus

  13. Its like you read my mind You appear to know a lot about this like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a little bit but other than that this is wonderful blog. A great read. Ill certainly be back. free spins no deposit

  14. Fabulous what a web site it is This webpage presents helpful information to us keep it up. free spins no deposit

  15. Thanks for the auspicious writeup. It in truth was a leisure account it. Look advanced to far introduced agreeable from you However how can we be in contact? free spins no deposit

  16. Attractive section of content. I just stumbled upon your site and in accession capital to assert that I get actually enjoyed account your blog posts. Anyway I will be subscribing to your feeds and even I achievement you access consistently rapidly. no deposit bonus

  17. Hi Im at work browsing your blog from my new iphone 3gs Just wanted to say I love reading your blog and look forward to all your posts Carry on the great work no deposit bonus

  18. Thank you a bunch for sharing this with all people you actually recognize what you are talking approximately Bookmarked. Kindly additionally seek advice from my website =). We could have a link exchange contract among us no deposit bonus

  19. This text is priceless. Where can I find out more? free spins no deposit

  20. I used to be able to find good information from your blog articles. no deposit bonus

  21. foreign online pharmacy: Online Pharm First – legit online pharmacy

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>