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

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.

Replies are listed 'Best First'.
Re^4: CGI.pm and tabindex
by ruzam (Curate) on Aug 31, 2006 at 06:05 UTC
    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?

        Sorry, should have got back to the list sooner. Turns out this is a previously identified bug in CGI.pm Tab index feature added to CGI.pm

        I've got version 3.08 installed.