An htm4l example - getting a date

Here is something that I've never used. In fact, I don't like it too much at all, I just wrote it to illustrate some of the power of m4 that you get by using htm4l.

The problem is to create a date-entry section on a form. Of course there's an easy way to do this, just use an ENTRY tag and deal with the result in your cgi script that handles the form. No problem, right? Right.

Here's something that's a bit different. It allows the entry via either pop-up menus or scrolling lists (which people using X windows may need to use if their font is too large to hold the 31 possible day numbers). The date entry are looks like this:

This was produced by a single line of htm4l code (centered in a FORM):

m4_mdy(`arrival', `3', `1990', `2000')

There is an equivalent m4_dmy macro which produces the identical thing, but in month, day, year order.

The arguments to the macro are as follows:

Variable suffix This is used as the suffix for the three name variables that will appear in the form's html. In the above example, the form will have variables arrival_month, arrival_month, and arrival_year. The program that processes your form should expect to deal with these variables as usual.
Font size This is used in a <font size="X"> command that precedes the generated html. If you give a value of zero, no font size-changing html is issued.
Starting year The first year you want to see in the list of selectable years.
Ending year The last year you want to see in the list of selectable years.
Scroll size This optional argument will cause htm4l to output html that makes each entry field a scrolling list rather than a popup menu. This variable determines how large each scrolling list is. In the above example, this argument is missing (see the next example though).

The above example did not provide a 5th argument, and so htm4l generated html that presents popup menus to the user. Here is an example with a 5th argument to set the size, with day, month, year order, and also with a small font.

It won't come as any surprise to hear that this was produced with the single line

m4_dmy(`birth', `1', `1900', `1996', `12')

This is probably usable by a wider range of people, since it is pretty much guaranteed to fit on any screen. Putting that many lines into a popup menu is asking for trouble.

The html generated by this example looks like this:

<font size="1"> <select name="birth_day" size="12"> <option>1 <option>2 <option>3 <option>4 <option>5 <option>6 <option>7 <option>8 <option>9 <option>10 <option>11 <option>12 <option>13 <option>14 <option>15 <option>16 <option>17 <option>18 <option>19 <option>20 <option>21 <option>22 <option>23 <option>24 <option>25 <option>26 <option>27 <option>28 <option>29 <option>30 <option>31 </select><select name="birth_month" size="12"> <option>January <option>February <option>March <option>April <option>May <option>June <option>July <option>August <option>September <option>October <option>November <option>December </select><select name="birth_year" size="12"> <option>1900 <option>1901 <option>1902 <option>1903 <option>1904 <option>1905 <option>1906 <option>1907 <option>1908 <option>1909 <option>1910 <option>1911 <option>1912 <option>1913 <option>1914 <option>1915 <option>1916 <option>1917 <option>1918 <option>1919 <option>1920 <option>1921 <option>1922 <option>1923 <option>1924 <option>1925 <option>1926 <option>1927 <option>1928 <option>1929 <option>1930 <option>1931 <option>1932 <option>1933 <option>1934 <option>1935 <option>1936 <option>1937 <option>1938 <option>1939 <option>1940 <option>1941 <option>1942 <option>1943 <option>1944 <option>1945 <option>1946 <option>1947 <option>1948 <option>1949 <option>1950 <option>1951 <option>1952 <option>1953 <option>1954 <option>1955 <option>1956 <option>1957 <option>1958 <option>1959 <option>1960 <option>1961 <option>1962 <option>1963 <option>1964 <option>1965 <option>1966 <option>1967 <option>1968 <option>1969 <option>1970 <option>1971 <option>1972 <option>1973 <option>1974 <option>1975 <option>1976 <option>1977 <option>1978 <option>1979 <option>1980 <option>1981 <option>1982 <option>1983 <option>1984 <option>1985 <option>1986 <option>1987 <option>1988 <option>1989 <option>1990 <option>1991 <option>1992 <option>1993 <option>1994 <option>1995 <option>1996 </select></font>

You obviously get quite a bit of html for your one line of htm4l.

If you don't like the way this looks, that's fine, I'm not particularly fond of it either. But at least it gives you an idea of what is possible and can be a starting point for your own customized macro.

Back to the htm4l home page. Back to the htm4l examples page.
© Terry Jones (terry <AT> Last modified: Mon Oct 2 02:21:32 CEST 2006