in reply to CGI.pm and tabindex

A quick read of the CGI.pm source code shows that the tabindex behavior is controlled in two ways: by setting a CGI package global called $TABINDEX, and when you explicitly pass in a -tabindex for each element. The bizarre part is that $TABINDEX is false by default and only gets set to true if -tabindex is passed to the constructor.

You may be able to turn off this behavior by setting $CGI::TABINDEX = 0 from your code, but it really isn't a good idea to muck around with a module's internals like that -- you're better off figuring out why this is happening.

The only explanation for this unexpected behavior that I can think of is that you are using the CGI module in a persistent environment (mod_perl, FastCGI, SpeedyCGI or whatever) and one of your other scripts is using the global -tabindex option, which CGI.pm is failing to reset between invocations for whatever reason.

Replies are listed 'Best First'.
Re^2: CGI.pm and tabindex
by Anonymous Monk on Aug 31, 2006 at 06:00 UTC
    but it really isn't a good idea to muck, around with a module's internals like that

    Unless you do it properly:

    local $CGI::TABINDEX = 0;
Re^2: CGI.pm and tabindex
by ruzam (Curate) on Aug 31, 2006 at 04:16 UTC
    Thanks. The persistent environment is a good lead, but in this case I don't believe it applies. I'll snoop around the CGI.pm source and see if a better explanation turns up. For now I've been passing -tabindex => '' into each element which effectively eliminates side effects from the browser, but is a pain in the back end. If I were a suspicious man I might suspect that Mandriva has taken some artistic license with the default behaviour of their packaged version. Or maybe it's just something simple that I've missed...
      Try the following one-liners on the command-line:
      perl -MCGI=:form, -e 'print textfield()'
      perl -MCGI=:form,:tabindex -e 'print textfield()'

      On my system, the first one outputs <input type="text" name="" /> without the tabindex while the second one includes the tabindex attribute: <input type="text" name="" tabindex="1"  />

      This is just a quick check if the defaults are for some reason different in your CGI.pm or whether there is something more mysterious going on. If your results from running these are the same as mine, then there must be something in your program or the environment it's running in that is triggering the strange tabindex behavior.

        Ok, from a quick check of CGI.pm, tabindex gets added to nearly every form element if flag $XHTML is true. Also according to the code, $XHTML is initialized to true unless it's specifically set off with 'use CGI qw( -no_xhtml );'.

        Is tabindex correct syntax for XHTML? Should XHTML be the default usage? Do I even want XHTML in the first place?

        Burning questions, but at least I have an out now.