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

  1. Umass India Pharm: Umass India Pharm – Umass India Pharm

  2. Umass India Pharm: Umass India Pharm – п»їlegitimate online pharmacies india

  3. buy prescription drugs from india: Umass India Pharm – world pharmacy india

  4. canadian medications: Nyu Pharm – canadian pharmacy victoza

  5. indian pharmacies safe Online medicine home delivery Online medicine order

  6. Unm Pharm: mexico pharmacies prescription drugs – reputable mexican pharmacies online

  7. trustworthy canadian pharmacy: canada drugs reviews – canadianpharmacyworld

  8. pharmacy website india: Umass India Pharm – Umass India Pharm

  9. india pharmacy mail order: best online pharmacy india – Umass India Pharm

  10. online mexico pharmacy USA legit mexican pharmacy for hair loss pills Unm Pharm

  11. Unm Pharm: buy antibiotics over the counter in mexico – buy kamagra oral jelly mexico

  12. Umass India Pharm: top 10 online pharmacy in india – Umass India Pharm

  13. Umass India Pharm: Umass India Pharm – indian pharmacies safe

  14. medication canadian pharmacy: Nyu Pharm – buying from canadian pharmacies

  15. best canadian pharmacy online: Nyu Pharm – buy canadian drugs

  16. canadian discount pharmacy: my canadian pharmacy review – the canadian pharmacy

  17. Umass India Pharm: Umass India Pharm – buy prescription drugs from india

  18. canada ed drugs: reliable canadian pharmacy – canadian pharmacies

  19. legit mexican pharmacy without prescription: rybelsus from mexican pharmacy – п»їmexican pharmacy

  20. pharmacy website india indian pharmacies safe best india pharmacy

  21. Unm Pharm: best online pharmacies in mexico – mexican drugstore online

  22. canadian pharmacy service: canadian pharmacy uk delivery – legit canadian pharmacy

  23. legitimate canadian pharmacy online Nyu Pharm 77 canadian pharmacy

  24. Umass India Pharm: Umass India Pharm – online pharmacy india

  25. Umass India Pharm: reputable indian pharmacies – buy medicines online in india

  26. my canadian pharmacy: canada rx pharmacy world – pharmacy in canada

  27. reputable canadian pharmacy canada online pharmacy cross border pharmacy canada

  28. india online pharmacy: Umass India Pharm – Umass India Pharm

  29. Nein, denn kostenlose Casinospiele sind im Grunde genommen die gleichen Spiele,
    die Sie in Online Casinos mit echtem Geld spielen können, jedoch ohne Ihr eigenes echtes
    Geld als Einsatz zu verwenden. Denn einige der kostenlosen Casinospiele stehen nur Spielern aus bestimmten Ländern zur Verfügung.

    Wenn Sie vor allem an Slotspielen interessiert sind, so können Sie jederzeit
    gerne unsere spezielle Seiten besuchen, die voller
    kostenloser Online Spielautomaten sind. Wenn Sie weiterlesen, werden Sie erfahren, wie Sie kostenlose Glücksspiele
    ohne Registrierung und ohne Download spielen können, ohne dabei Ihr eigenes Bankkonto zu
    belasten. Die Macher wollten allen Casinospielern die Möglichkeit geben ihre Lieblingsspiele
    kostenlos testen zu können. Da man alle Casinospiele kostenlos Online Spielen kann, ist
    diese Seite für begeisterte Casinospieler ein Muss!

    In Deutschland gebaut – für die ganze Welt spielbar. Auch da natürlich kostenlos.
    Meine Begeisterung für das Glücksspiel entfachte während meines ersten Besuchs in der
    Spielbank Dortmund-Hohensyburg, und seitdem habe ich die Welt der Casinos und Wetten intensiv erkundet.

    Echtgeld Spielautomaten verlangen einen Geldeinsatz, der
    riskiert wird, um mögliche Gewinne zu erzielen.

    References:
    https://online-spielhallen.de/dolly-casino-promo-code-ihr-schlussel-zu-exklusiven-vorteilen/

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>