in reply to How to use CGI.pm to label a checkbox

I can't help with your immediate problem - CGI seems to expect that check boxes always need labels. However, in the longer term you may find using HTML::Template or other such templating module is a better solution for generating dynamic HTML than using CGI's HTML generation facilities.

True laziness is hard work
  • Comment on Re: How to use CGI.pm to label a checkbox

Replies are listed 'Best First'.
Re^2: How to use CGI.pm to label a checkbox
by Anonymous Monk on Oct 12, 2011 at 10:11 UTC

    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.

      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

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