in reply to Re: How to use CGI.pm to label a checkbox
in thread How to use CGI.pm to label a checkbox

Thank you. It seems that CGI.pm always puts the label tag around input elements. This is a problem for my jQuery stuff. Regarding the template, I have thousands of lines in our application using CGI.pm with very complex processing before producing the HTML. I don't want to switch to a templating system because I should work a lot to replicate (?) the same flexibility. I can obviously fix this by just printing the HTML code instead of using CGI.pm in that specific step, but this is a pity.

  • Comment on Re^2: How to use CGI.pm to label a checkbox

Replies are listed 'Best First'.
Re^3: How to use CGI.pm to label a checkbox
by GrandFather (Saint) on Oct 12, 2011 at 10:27 UTC

    It's like any technology switch when you've invested substantial time into an old system: there is real pain up front and huge fear of a new way of doing things, but the longer you put off the change the worse the problem gets and the longer it is until you reap the rewards.

    There are many templating systems around and pretty much any of them will put you way ahead of the CGI in line approach to generating dynamic HTML. The big immediate advantage of using templates is they generally make it much easier to maintain the HTML independently of the code, and maintain the code independently of the HTML. It makes the logic of the code clearer and allows easier validation of the HTML.

    True laziness is hard work
Re^3: How to use CGI.pm to label a checkbox
by Your Mother (Archbishop) on Oct 12, 2011 at 13:54 UTC

    If you find yourself tweaking HTML to accommodate jQuery, you are probably doing something wrong. The selcctors are powerful enough to handle anything. $("input[name='whatever']") or $(".someWrapper input[type='checkbox']") for example won't care about the labels, and if you need to for some reason, you can walk back up with parent(s) or closest or whatever.

    If anything the wrapping labels offer more flexibility because every level of tag isolation/lineage gives a chance for enhanced CSS that still requires dummy tags in most browsers (double backgrounds, e.g.).