Tuesday, July 25, 2006

Dynamically add/subtract upload fields to form: Chapter 1, the frontend

The assignment: create a webpage which permits faculty to upload digital course reserves materials, using XHTML frontend and Perl backend, then attach those uploads to an email sent to a clearinghouse mailbox.

The complications:
  1. backend needs to be agnostic towards how many uploads are being sent, preferably no iteration over numbered input name attributes
  2. frontend is proper XHTML, therefore adding new input elements can't use document.write JavaScript methods

Let's deal with the frontend first. XHTML deprecates document.write because it breaks the idea of XHTML as a properly formed XML document: anything could be inserted into your webpage no matter how well or poorly formed it is. If I'm not mistaken XHTML served as its correct MIMEtype results in browsers throwing errors when they encounter document.write.

Fortunately, XHTML nominally being XML, it supports XML's methods for inserting, removing and changing internal content. Let's take a look at some sample JavaScript:

No comments: