in reply to Re: CGI.pm and tabindex
in thread CGI.pm and tabindex

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

Replies are listed 'Best First'.
Re^3: CGI.pm and tabindex
by dirving (Friar) on Aug 31, 2006 at 04:42 UTC
    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.

        Read CGI.pm a little closer :) Tabindex will only get added if $XHTML is true, but it won't necessarily get added -- even though from looking at just the line  return $XHTML ? qq(<input type="$tag" name="$name" $tabindex$value$s$m$other />) this seems to be the case, if look you up a few lines, $tabindex gets set by calling the element_tab method, which returns an empty string unless -tabindex was passed at some point. So it looks like you can use the -no_xhtml switch to work around this, but there is still something strange going on.

        If I had to guess, I'd say that tabindex was added to the HTML standard when XHTML came out, which is why it does this. XHTML should probably be the default since it is the most current standard, although if you decide to use HTML4 or whatever there is nothing inherently wrong with that.

        Out of curiosity, what version of CGI.pm do you have? I'm looking at 3.15 here... it's possible we're looking at totally different things. Also, did you try the two one-liners I suggested -- and if you did, what were the results?