CiTi · Computer Coding · Year Two · Unit 1

Solution Walkthrough: Roster Admin

The finished inline edit form, built in three parts: layout, data, and JavaScript

The big idea: one page, one form per student

The whole project is one file, assignments/week2.html. It lists every student, and each student is a closed row that opens into its own little form. Press Save and that form is sent back to the same page. The top of the page sees what was sent, changes roster.db, and sends the browser back to a clean copy of the page.

  1. Layout (CSS). Make it readable: an open-and-close row for each student, grouped fields, a toolbar, and a phone-width version. No data yet. Go →
  2. WebDNA forms. Fill the rows from a search, then make Add, Save, and Delete work with append, replace, and delete. Go →
  3. JavaScript. Browser helpers: close one row, expand or collapse every row, sort the list by clicking a column, plus the delete confirm and the unsaved warning. Go →
How to use this page Each step shows only the code that step adds and why it works. The complete file is at the bottom under Full Solution, with a Copy button. Your colors can be your own; the jobs the page does cannot change.

1Layout (CSS): what the admin sees

In Part 1 there is no database. You type sample values into the HTML so you can see how a full page looks. Below, a sample student called Jordan Diaz stands in for the real data that arrives in Part 2.

Step 1: one student row that opens and closes

The pair <details> and <summary> makes a row that opens and closes with no JavaScript. The <summary> is the line you always see. Everything else inside <details> is hidden until you click. Here, the hidden part is the student's edit form.

one student row (Part 1, sample values)
<details class="rec"> <summary> <span class="sku">#3</span> <span class="name">Jordan Diaz</span> <span class="small hidesm">jdiaz</span> <span class="small hidesm">2nd Year</span> <span class="small hidesm">AM</span> <span class="small hidesm">Oswego</span> <span class="small hidesm">12</span> <span><span class="badge">Active</span></span> </summary> <form class="fields" method="post" action="week2.html"> <input type="hidden" name="skuvar" value="3"> <input type="hidden" name="sort" value="first"> <input type="hidden" name="show" value="active"> <div class="grid"> <fieldset><legend>Name</legend> <label>First name<input name="fname" required value="Jordan"></label> <label>Last name<input name="lname" required value="Diaz"></label> </fieldset> <fieldset><legend>Login</legend> <label>Username<input name="uname" required autocomplete="off" value="jdiaz"></label> <label>Password<input name="pword" required autocomplete="off" value="blue42"></label> <label>Email<input type="email" name="email" value="jdiaz@example.org"></label> </fieldset> <fieldset><legend>Class</legend> <label>Session<select name="session"> <option value="1" selected>AM</option> <option value="0">PM</option> </select></label> <label>School year<select name="schoolyear"> <option value="2025">2025</option><option value="2026" selected>2026</option><option value="2027">2027</option> </select></label> <label>Level<select name="level"> <option value="1">1st Year</option> <option value="2" selected>2nd Year</option> <option value="3">Teacher</option> <option value="4">Admin</option> <option value="5">Operator</option> </select></label> <label>Computer #<input type="number" name="computernum" min="0" value="12"></label> </fieldset> <fieldset><legend>Account</legend> <label>Status<select name="status"> <option value="1" selected>Active</option> <option value="0">Inactive</option> </select></label> <label>Chat allowed<select name="chatallowed"> <option value="1" selected>Yes</option> <option value="0">No</option> </select></label> <label>Admin access<select name="adminaccess"> <option value="0" selected>Student</option> <option value="1">Admin</option> </select></label> <label>District<select name="r_district" required> <option value="1">APW</option><option value="2">Central Square</option><option value="3">Fulton</option><option value="6" selected>Oswego</option> </select></label> </fieldset> <fieldset><legend>Folder</legend> <label>Student directory<input name="studentdir" value="/citi/coding/2027/2/jd/"></label> </fieldset> </div> <div class="actions"> <span class="key">Key: 1760812345</span> <button type="submit" name="action" value="delete" class="danger" formnovalidate>Delete</button> <button type="reset" class="ghost">Undo changes</button> <button type="submit" name="action" value="replace">Save</button> </div> </form> </details>
Things to notice
  • One form per student, wrapping the whole record. Each form sends only its own student's values.
  • <fieldset> and <legend> group 15 fields into 5 titled boxes: Name, Login, Class, Account, Folder.
  • Every box sits inside its <label>. Clicking the words puts the cursor in the box, and the admin never has to guess what a box is for.
  • The right control for each field: type="email", type="number", and a dropdown for anything stored as a code (1 = AM, 0 = PM).
  • The record number and KEY are shown as text, not boxes, because no one should edit them.

Step 2: the page base

Colors live in variables at the top (--accent, --warn, and so on). Change one line and the whole page follows. box-sizing:border-box makes padding count inside a box's width, so 100%-wide inputs never poke out of their column.

CSS: variables, page, header
:root{ --bg:#f4f6f8; --card:#fff; --ink:#1d2733; --muted:#66727f; --line:#d9dfe5; --accent:#1f7a4d; --accent-soft:#e3f3ea; --warn:#b42318; --warn-soft:#fdecea; --dirty:#f5a524; --dirty-soft:#fff6e5; } *{box-sizing:border-box} body{margin:0;font:15px/1.4 system-ui,-apple-system,Segoe UI,Roboto,sans-serif;background:var(--bg);color:var(--ink)} header{background:var(--accent);color:#fff;padding:18px 24px} header h1{margin:0;font-size:22px} header p{margin:4px 0 0;opacity:.85;font-size:13px} main{max-width:1200px;margin:0 auto;padding:16px}

Step 3: messages, toolbar, inputs, and buttons

Save is solid green. .ghost buttons (Undo, Clear) are white, so they read as less important. .danger (Delete) is white with a red outline and turns solid red on hover, so it looks risky before anyone clicks it.

CSS: messages, toolbar, controls, buttons
.msg{padding:10px 14px;border-radius:8px;margin-bottom:14px;background:var(--accent-soft);border:1px solid var(--accent)} .msg.err{background:var(--warn-soft);border-color:var(--warn);color:var(--warn)} .toolbar{display:flex;flex-wrap:wrap;gap:10px;align-items:center;margin-bottom:14px} .toolbar form{display:flex;gap:8px;flex-wrap:wrap;align-items:center} .count{margin:0 0 8px;color:var(--muted);font-size:13px} input,select,button{font:inherit} input,select{padding:6px 8px;border:1px solid var(--line);border-radius:6px;background:#fff;width:100%} input:focus,select:focus{outline:2px solid var(--accent);outline-offset:-1px} .toolbar input,.toolbar select{width:auto} button,.btn{padding:7px 14px;border-radius:6px;border:1px solid var(--accent);background:var(--accent);color:#fff;cursor:pointer} button.ghost{background:#fff;color:var(--accent)} button.danger{background:#fff;color:var(--warn);border-color:var(--warn)} button.danger:hover{background:var(--warn);color:#fff}

Step 4: the summary row is a grid

The summary and the column headings above it use the same grid-template-columns, so the headings line up with every row. The browser's default triangle is hidden (list-style:none and ::-webkit-details-marker), because the whole row is the click target. An inactive student gets a gray, crossed-out name. A .dirty row gets an orange border and the word “(unsaved)”; JavaScript adds that class in Part 3.

CSS: rows, headings, badges, inactive and unsaved
details{background:var(--card);border:1px solid var(--line);border-radius:10px;margin-bottom:8px} details.add{border:2px dashed var(--accent)} details.add > summary{color:var(--accent);font-weight:600} summary{list-style:none;cursor:pointer;padding:10px 14px;display:grid;grid-template-columns:50px 1.4fr 1fr 1fr 1fr 1fr 70px 80px;gap:10px;align-items:center} summary::-webkit-details-marker{display:none} details.add > summary{display:block} summary .sku{color:var(--muted);font-size:13px} summary .name{font-weight:600} summary .small{color:var(--muted);font-size:13px} .badge{display:inline-block;padding:2px 8px;border-radius:99px;font-size:12px;background:var(--accent-soft);color:var(--accent);text-align:center} .badge.off{background:#eceff2;color:var(--muted)} details.inactive summary .name{color:var(--muted);text-decoration:line-through} details.dirty{border-color:var(--dirty);background:var(--dirty-soft)} details.dirty summary .name::after{content:" (unsaved)";color:var(--dirty);font-weight:400;font-size:12px} .listhead{display:grid;grid-template-columns:50px 1.4fr 1fr 1fr 1fr 1fr 70px 80px;gap:10px;padding:0 15px 6px;font-size:12px;text-transform:uppercase;letter-spacing:.04em;color:var(--muted)}

Step 5: the edit form inside a row

repeat(auto-fill, minmax(200px, 1fr)) fits as many 200px-wide groups on a line as the screen allows and wraps the rest. That one line makes the form work from a phone to a wide monitor. margin-right:auto on the KEY text pushes the buttons to the right.

CSS: form grid, groups, labels, button row
.fields{padding:4px 14px 14px;border-top:1px solid var(--line)} .grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:10px 14px;margin-top:10px} fieldset{border:1px solid var(--line);border-radius:8px;padding:8px 10px 10px;margin:0} legend{font-size:12px;font-weight:600;text-transform:uppercase;color:var(--muted);padding:0 4px} label{display:block;font-size:12px;color:var(--muted);margin-top:6px} label:first-of-type{margin-top:0} .actions{display:flex;gap:8px;justify-content:flex-end;margin-top:12px;align-items:center} .actions .key{margin-right:auto;font-size:12px;color:var(--muted)} .sorth{all:unset;cursor:pointer;text-transform:inherit;letter-spacing:inherit} .sorth:hover,.sorth.on{color:var(--accent);text-decoration:underline} .empty{padding:30px;text-align:center;color:var(--muted)}

Step 6: phone width

Under 760px wide, the column headings hide, the summary shrinks to three columns (#, name, status), and every cell with class="hidesm" disappears. Nothing scrolls sideways.

CSS: small screens
@media (max-width:760px){ .listhead{display:none} summary{grid-template-columns:40px 1fr auto} summary .hidesm{display:none} }

Step 7: the Add form, toolbar, and headings

The Add form is the same fields, empty, inside its own <details class="add"> with a dashed border. It has sensible defaults: this year, Active, Student. The toolbar's dropdowns don't do anything in Part 1; Part 2 makes them work.

Add form (Part 1)
<details class="add" > <summary>+ Add a new student</summary> <form class="fields" method="post" action="week2.html"> <input type="hidden" name="sort" value="first"> <input type="hidden" name="show" value="active"> <div class="grid"> <fieldset><legend>Name</legend> <label>First name<input name="fname" required value=""></label> <label>Last name<input name="lname" required value=""></label> </fieldset> <fieldset><legend>Login</legend> <label>Username<input name="uname" required autocomplete="off" value=""></label> <label>Password<input name="pword" required autocomplete="off" value=""></label> <label>Email<input type="email" name="email" value=""></label> </fieldset> <fieldset><legend>Class</legend> <label>Session<select name="session"><option value="1">AM</option><option value="0">PM</option></select></label> <label>School year<select name="schoolyear"> <option value="2025">2025</option><option value="2026" selected>2026</option><option value="2027">2027</option> </select></label> <label>Level<select name="level"> <option value="1">1st Year</option><option value="2">2nd Year</option><option value="3">Teacher</option><option value="4">Admin</option><option value="5">Operator</option> </select></label> <label>Computer #<input type="number" name="computernum" min="0" value=""></label> </fieldset> <fieldset><legend>Account</legend> <label>Status<select name="status"><option value="1">Active</option><option value="0">Inactive</option></select></label> <label>Chat allowed<select name="chatallowed"><option value="1">Yes</option><option value="0">No</option></select></label> <label>Admin access<select name="adminaccess"><option value="0">Student</option><option value="1">Admin</option></select></label> <label>District<select name="r_district" required> <option value="">Choose a district</option> <option value="1">APW</option><option value="2">Central Square</option><option value="3">Fulton</option><option value="6">Oswego</option> </select></label> </fieldset> <fieldset><legend>Folder</legend> <label>Student directory<input name="studentdir" placeholder="/citi/coding/2026/1/xx/" value=""></label> </fieldset> </div> <div class="actions"> <button type="reset" class="ghost">Clear</button> <button type="submit" name="action" value="append">Add student</button> </div> </form> </details>
toolbar (Part 1)
<div class="toolbar"> <form method="get" action="week2.html"> <label class="small" style="margin:0">Show <select name="show" onchange="this.form.submit()"> <option value="active" selected>Active</option> <option value="inactive">Inactive</option> <option value="all">All</option> </select> </label> <label class="small" style="margin:0">Sort <select name="sort" onchange="this.form.submit()"> <option value="first" selected>First name</option> <option value="last">Last name</option> <option value="sku">Record #</option> <option value="computer">Computer #</option> </select> </label> </form> <button type="button" class="ghost" id="expand">Expand all</button> </div>
column headings
<div class="listhead"><span>#</span><span>Name</span><span>Username</span><span>Level</span><span>Session</span><span>District</span><span>PC</span><span>Status</span></div>
Part 1 is done when Copy the sample row 3 or 4 times with different people, make one inactive (class="rec inactive"), and check that a narrow window never scrolls sideways.

2WebDNA: forms with search, append, and replace

WebDNA runs on the server before the browser sees the page. The file is laid out top to bottom like this:

  1. Settings Database paths and defaults.
  2. Processing If a form was sent, do the add, save, or delete, then redirect.
  3. The HTML from Part 1 Now filled from a search.
  4. Close the databases At the very end.

Step 1: settings

Every path is typed once, in a text variable. Everywhere else uses [dbpath], so moving the database means changing one line.

top of week2.html
[text]dbname=roster.db[/text] [text]dbpath=databases/roster.db[/text] [text]dbdistrict=databases/district.db[/text] [text]thispage=week2.html[/text]

Step 2: the two values that can be missing

A submitted form always sends every field inside it. An empty box sends an empty value, so [fname] is simply blank. Those fields need no check. And on a plain visit, the processing blocks below don't run, so their fields are never printed.

sort and show are different: they arrive in the address bar, from the toolbar or the redirect. A plain visit to week2.html sends neither. A variable that was never sent prints its own name, so [sort] would show the text “[sort]”. So the test is: does the value still match its own name? [raw][sort][/raw] prints the name itself, brackets and all, without running it. If [sort] equals that, it was never sent, and the line blanks it.

Why both sides are inside [url]: [showif] reads <, >, and ! as comparisons. Someone could type ?sort=a<b in the address bar, and the test would read it as “less than” and give the wrong answer. Encoded, < becomes %3C and [ becomes %5B, so both sides are plain text and the test compares them letter for letter.

Two versions of the same test
  • [showif [v]=[raw][v][/raw]] is fine when the value can only ever be a fixed code you control.
  • [showif [url][v][/url]=[url][raw][v][/raw][/url]] is the safe one for anything a person can type or put in the address bar. When in doubt, use this one.

The same thing happens if you forget to put a field in a form, or with an unchecked checkbox (the browser sends nothing for it). If you ever see a bracketed name on your page, look for one of those three causes.

blank never-sent fields
[!] ---- sort and show come from the address bar (the toolbar and the redirect). A plain visit to week2.html sends neither, and a variable that was never sent prints its own name. If the value still matches its own name, it was never sent, so blank it. Both sides are url-encoded so a < > ! in the address bar is compared as text, not read as an operator. Fields inside a form need no check: a submitted form always sends them, empty boxes as empty. ---- [/!] [showif [url][sort][/url]=[url][raw][sort][/raw][/url]][text]sort=[/text][/showif] [showif [url][show][/url]=[url][raw][show][/raw][/url]][text]show=[/text][/showif] [text]msgtype=[/text]

Step 3: defaults and the school-year range

sort and show get printed back into the page (the hidden inputs and the toolbar), so only known values get through. Each line asks “is it exactly last?”, “exactly sku?”, and so on; anything else, including empty, becomes the default: Active students sorted by first name. Without this, a crafted link like ?sort=x" onfocus="... would be written into your page as working HTML, and run on the admin's screen. Never print a value from the address bar unless you have checked it against a list.

The year dropdown runs from 5 years back to 5 years ahead of this year, worked out with [math], so it never needs editing. The a_ variables hold what the admin typed into Add, so a refused add can refill the form.

defaults
[!] ---- View settings: only known values get through. Anything else (empty, junk, or a crafted link) becomes the default: first name, active. sort and show are written back into the page, so this also stops a link from putting its own HTML or script into the hidden inputs. ---- [/!] [text]v=first[/text] [showif [url][sort][/url]=last][text]v=last[/text][/showif] [showif [url][sort][/url]=sku][text]v=sku[/text][/showif] [showif [url][sort][/url]=computer][text]v=computer[/text][/showif] [text]sort=[v][/text] [text]v=active[/text] [showif [url][show][/url]=inactive][text]v=inactive[/text][/showif] [showif [url][show][/url]=all][text]v=all[/text][/showif] [text]show=[v][/text] [!] ---- School year dropdown range: 5 back, 5 ahead ---- [/!] [text]thisyear=[date %Y][/text] [text]startyear=[math][thisyear]-5[/math][/text] [text]endyear=[math][thisyear]+5[/math][/text] [!] ---- Add-form memory: if an add fails, refill what was typed ---- [/!] [text]addopen=[/text] [text]note=[/text] [text]a_fname=[/text][text]a_lname=[/text][text]a_uname=[/text][text]a_pword=[/text] [text]a_studentdir=[/text][text]a_computernum=[/text][text]a_email=[/text]

Step 4: one form, several jobs

Every form posts to the page itself. The buttons carry the job: a button's name and value are only sent for the button that was pressed. So one student form sends action=replace for Save, or action=delete for Delete. The hidden skuvar says which record. (Never name a form field sku; that name belongs to WebDNA.)

top of each student form
<form class="fields" method="post" action="[thispage]" data-name="[fname] [lname]"> <input type="hidden" name="skuvar" value="[sku]"> <input type="hidden" name="sort" value="[sort]"> <input type="hidden" name="show" value="[show]">
the buttons
<div class="actions"> <span class="key">Key: [key]</span> <button type="submit" name="action" value="delete" class="danger" formnovalidate>Delete</button> <button type="reset" class="ghost">Undo changes</button> <button type="submit" name="action" value="replace">Save</button> <button type="button" class="ghost close">Close</button> </div>

formnovalidate on Delete lets it go through even if a required box is empty.

Step 5: Add with append

First a search for the username. [numfound] is how many records matched: 0 means the name is free. Then [append] writes a new record. autonumber=sku lets WebDNA number it, and [cart] makes a unique KEY.

Every value is wrapped in [url]...[/url]. Inside append, & separates fields and = separates a name from its value. Without encoding, “O'Brien & Sons” saves as “O'Brien ” and a password like a&b=c is cut off.

After a good add: [closedatabase] writes the file, and [redirect] sends the browser back to a plain copy of the page. Now Refresh just reloads the list and can never add the student twice. If the name is taken, nothing is written: a red note is set, the Add form is told to stay open, and the typed values are kept.

ADD
[!] ---- ADD (append) - refuse a duplicate username ---- [/!] [showif [action]=append] [text]dupe=0[/text] [search db=[dbpath]&eqUNAMEdatarq=[url][uname][/url]&max=1][text]dupe=[numfound][/text][/search] [showif [dupe]=0] [append db=[dbpath]&autonumber=sku]FNAME=[url][fname][/url]&LNAME=[url][lname][/url]&KEY=[cart]&UNAME=[url][uname][/url]&PWORD=[url][pword][/url]&SESSION=[url][session][/url]&SCHOOLYEAR=[url][schoolyear][/url]&STATUS=[url][status][/url]&STUDENTDIR=[url][studentdir][/url]&LEVEL=[url][level][/url]&COMPUTERNUM=[url][computernum][/url]&CHATALLOWED=[url][chatallowed][/url]&EMAIL=[url][email][/url]&ADMINACCESS=[url][adminaccess][/url]&r_district=[url][r_district][/url][/append] [closedatabase db=[dbpath]] [redirect [thispage]?sort=[url][sort][/url]&show=[url][show][/url]&msg=added] [/showif] [hideif [dupe]=0] [text]note=Username "[uname]" is already taken. Nothing was added.[/text] [text]msgtype=err[/text] [text]addopen=open[/text] [text]a_fname=[fname][/text][text]a_lname=[lname][/text][text]a_uname=[uname][/text][text]a_pword=[pword][/text] [text]a_studentdir=[studentdir][/text][text]a_computernum=[computernum][/text][text]a_email=[email][/text] [/hideif] [/showif]

Step 6: Save with replace

[replace] changes one record, found by eqSKUdatarq= its record number. The duplicate check has one extra condition: the username may match this student (neSKUdatarq means “record number is not this one”) but nobody else. KEY is left out on purpose so it never changes.

SAVE
[!] ---- SAVE (replace) - username must not belong to another record ---- [/!] [showif [action]=replace] [text]dupe=0[/text] [search db=[dbpath]&eqUNAMEdatarq=[url][uname][/url]&neSKUdatarq=[url][skuvar][/url]&max=1][text]dupe=[numfound][/text][/search] [showif [dupe]=0] [replace db=[dbpath]&eqSKUdatarq=[url][skuvar][/url]]FNAME=[url][fname][/url]&LNAME=[url][lname][/url]&UNAME=[url][uname][/url]&PWORD=[url][pword][/url]&SESSION=[url][session][/url]&SCHOOLYEAR=[url][schoolyear][/url]&STATUS=[url][status][/url]&STUDENTDIR=[url][studentdir][/url]&LEVEL=[url][level][/url]&COMPUTERNUM=[url][computernum][/url]&CHATALLOWED=[url][chatallowed][/url]&EMAIL=[url][email][/url]&ADMINACCESS=[url][adminaccess][/url]&r_district=[url][r_district][/url][/replace] [closedatabase db=[dbpath]] [redirect [thispage]?sort=[url][sort][/url]&show=[url][show][/url]&msg=saved] [/showif] [hideif [dupe]=0] [text]note=Username "[uname]" belongs to another student. Record #[skuvar] was NOT saved.[/text] [text]msgtype=err[/text] [/hideif] [/showif]

Step 7: Delete

DELETE
[!] ---- DELETE ---- [/!] [showif [action]=delete] [delete db=[dbpath]&eqSKUdatarq=[url][skuvar][/url]] [closedatabase db=[dbpath]] [redirect [thispage]?sort=[url][sort][/url]&show=[url][show][/url]&msg=deleted] [/showif]

Step 8: the search that fills the list

The toolbar sends show and sort. These lines turn each choice into a piece of the search. Text fields sort as text, where 10 comes before 2, so record number and computer number add type=num. neSKUdatarq=findall is how you ask for every record.

build the search
[!] ---- Build the search pieces from sort + show ---- [/!] [text]sortq=FNAMEsort=1&LNAMEsort=2[/text] [showif [sort]=last][text]sortq=LNAMEsort=1&FNAMEsort=2[/text][/showif] [showif [sort]=sku][text]sortq=SKUsort=1&SKUtype=num[/text][/showif] [showif [sort]=computer][text]sortq=COMPUTERNUMsort=1&COMPUTERNUMtype=num[/text][/showif] [text]showq=eqSTATUSdatarq=1[/text] [showif [show]=inactive][text]showq=eqSTATUSdatarq=0[/text][/showif] [showif [show]=all][text]showq=neSKUdatarq=findall[/text][/showif]

The toolbar dropdowns pre-select the current choice and submit themselves on change. With JavaScript off, the admin picks a value and presses Enter.

toolbar dropdowns
<select name="show" onchange="this.form.submit()"> <option value="active"[showif [show]=active] selected[/showif]>Active</option> <option value="inactive"[showif [show]=inactive] selected[/showif]>Inactive</option> <option value="all"[showif [show]=all] selected[/showif]>All</option> </select>

Then the search runs, and the Part 1 row goes inside [founditems], which repeats it once per student. [numfound] gives the count, and the [showif] adds the “s” unless it is exactly 1.

open the search
[search db=[dbpath]&[showq]&[sortq]] <p class="count">[numfound] student[showif [numfound]!1]s[/showif]</p> <div class="listhead"><button type="button" class="sorth" data-key="sku" data-type="num">#</button><button type="button" class="sorth" data-key="first">Name</button><span>Username</span><span>Level</span><span>Session</span><span>District</span><button type="button" class="sorth" data-key="pc" data-type="num">PC</button><span>Status</span></div> <div id="list">

Step 9: show words, not codes

The database stores 1; the admin should read “AM.” A [showif] for each code prints the word. For the district, [lookup] finds the row in district.db whose sku equals this student's r_district and returns its name. (It takes value=; any other spelling quietly returns nothing.)

summary row
<summary> <span class="sku">#[sku]</span> <span class="name">[fname] [lname]</span> <span class="small hidesm">[uname]</span> <span class="small hidesm">[showif [level]=1]1st Year[/showif][showif [level]=2]2nd Year[/showif][showif [level]=3]Teacher[/showif][showif [level]=4]Admin[/showif][showif [level]=5]Operator[/showif]</span> <span class="small hidesm">[showif [session]=1]AM[/showif][showif [session]=0]PM[/showif]</span> <span class="small hidesm">[lookup db=[dbdistrict]&lookInField=sku&value=[r_district]&returnField=district&notFound=Unknown]</span> <span class="small hidesm">[computernum]</span> <span>[showif [status]=1]<span class="badge">Active</span>[/showif][showif [status]=0]<span class="badge off">Inactive</span>[/showif]</span> </summary>

Step 10: every dropdown opens on the saved value

Each option asks “is this the student's value?” and adds selected if so.

pre-selected dropdown
<label>Session<select name="session"> <option value="1"[showif [session]=1] selected[/showif]>AM</option> <option value="0"[showif [session]=0] selected[/showif]>PM</option> </select></label>

The school year is the one students get wrong. Inside [loop], compare [index] to the record's year (saved in rowyear first), not to this year. Compare to this year and every Save quietly changes the student's year.

school year (student form)
<label>School year<select name="schoolyear"> [text]rowyear=[schoolyear][/text] [loop start=[startyear]&end=[endyear]]<option value="[index]"[showif [index]=[rowyear]] selected[/showif]>[index]</option>[/loop] </select></label>

The district dropdown is a search inside a search. Inside the district search, [sku] means the district's sku. So the student's r_district is saved in rowdist before the inner search starts. The select is named r_district to match the database field.

district (student form)
[text]rowdist=[r_district][/text] <label>District<select name="r_district" required> [search db=[dbdistrict]&neSKUdatarq=findall&districtsort=1][founditems]<option value="[sku]"[showif [sku]=[rowdist]] selected[/showif]>[district]</option>[/founditems][/search] </select></label>

The Add form uses the same two lists, defaulting to this year and an empty “Choose a district”:

school year and district (Add form)
<label>School year<select name="schoolyear"> [loop start=[startyear]&end=[endyear]]<option value="[index]"[showif [index]=[thisyear]] selected[/showif]>[index]</option>[/loop] </select></label> <label>District<select name="r_district" required> <option value="">Choose a district</option> [search db=[dbdistrict]&neSKUdatarq=findall&districtsort=1][founditems]<option value="[sku]">[district]</option>[/founditems][/search] </select></label>

Step 11: messages are code words

The redirect sends msg=added, not the sentence. The page decides what each code word says. If the page printed whatever text was in the address bar, anyone could email an admin a link that puts their own words, or a script, on your page.

The address bar can hold anything, so msg is compared inside [url]. A < or > in a raw value is read as a less-than or greater-than test, and ?msg=<b>hi would print a wrong message. Encoded, it is just text that matches nothing.

messages
[!] ---- Messages come back as fixed codes, never as page text from the URL ---- [/!] [showif [url][msg][/url]=added][text]note=Student added.[/text][/showif] [showif [url][msg][/url]=saved][text]note=Changes saved.[/text][/showif] [showif [url][msg][/url]=deleted][text]note=Student deleted.[/text][/showif] [showif [note]!]<div class="msg[showif [msgtype]=err] err[/showif]">[note]</div>[/showif]

Step 12: close everything

End the search and show a friendly note when no one matches:

end of the list
[/founditems] </div> [showif [numfound]=0]<div class="empty">No students match this view.</div>[/showif] [/search]

The very last lines of the file. WebDNA keeps a database in memory; closing it writes it to the file, so your changes stick and a fresh upload isn't overwritten.

last lines of week2.html
[closedatabase db=[dbpath]] [closedatabase db=[dbdistrict]]
Test it like an admin Do every test on a student you added yourself. Try adding O'Brien & Sons with password a&b=c, the same username twice, a Save, a Refresh, a Delete, and Sort by Computer #. Then View Source: there should be no square brackets anywhere.

3JavaScript: collapse, collapse all, and sorting

JavaScript only helps in the browser. It never saves anything; WebDNA already does that. Turn JavaScript off and the page must still list, add, save, and delete.

No square brackets in your script WebDNA reads the whole file first, script included, and can treat anything in square brackets as a tag. This script is written without any: getAttribute('data-' + key) instead of bracket lookups, and forEach instead of indexes. The script goes just before </body>, so every row already exists when it runs.

Step 1: find the rows

script
var recs = document.querySelectorAll('details.rec');

Step 2: simple collapse (one row)

A <details> element has an open property: true is open, false is closed. Each row gets a Close button at the bottom of its form, so the admin doesn't have to scroll back up to the summary. closest('details') walks up from the button to the row it belongs to. type="button" matters: without it, the button would submit the form.

add to the button row
<button type="button" class="ghost close">Close</button>
script
// ---- Simple collapse: the Close button shuts its own row ---- document.querySelectorAll('details.rec .close').forEach(function (b) { b.addEventListener('click', function () { b.closest('details').open = false; }); });

Step 3: expand all / collapse all

One button does both jobs. Its own words say which job is next: if it says “Expand all,” set every row's open to true and change the words to “Collapse all.” The ? : picks between two values in one line.

script
// ---- Expand / collapse all ---- var expand = document.getElementById('expand'); expand.addEventListener('click', function () { var open = expand.textContent === 'Expand all'; recs.forEach(function (d) { d.open = open; }); expand.textContent = open ? 'Collapse all' : 'Expand all'; });

Step 4: sort by clicking a column heading

The WebDNA Sort dropdown reloads the page. This sort happens instantly in the browser. Three pieces make it work:

  1. The values to sort by go on each row as data- attributes, written by WebDNA:
each row (replaces the plain details line)
<details class="rec[showif [status]=0] inactive[/showif]" data-sku="[sku]" data-first="[fname] [lname]" data-pc="[computernum]">
  1. The sortable headings become buttons that say which attribute to sort by, and whether it is a number. The rows are wrapped in <div id="list"> (close it right after [/founditems]) so the script knows where they live.
column headings (replaces the Part 1 headings)
<div class="listhead"><button type="button" class="sorth" data-key="sku" data-type="num">#</button><button type="button" class="sorth" data-key="first">Name</button><span>Username</span><span>Level</span><span>Session</span><span>District</span><button type="button" class="sorth" data-key="pc" data-type="num">PC</button><span>Status</span></div>
  1. The script sorts and re-adds the rows. Array.from makes a sortable list of rows. sort compares two rows at a time: numbers by subtracting (so 2 comes before 10), text with localeCompare. Multiplying by dir (1 or -1) flips the order when the same heading is clicked again. appendChild on a row that is already in the list moves it to the end, so adding them back in sorted order rebuilds the list.
script
// ---- Sort the list in the browser: click a column header ---- var list = document.getElementById('list'); var lastKey = '', dir = 1; document.querySelectorAll('.sorth').forEach(function (h) { h.addEventListener('click', function () { var key = h.dataset.key; var isNum = h.dataset.type === 'num'; dir = (key === lastKey) ? -dir : 1; // same header again = reverse lastKey = key; var rows = Array.from(list.querySelectorAll('details.rec')); rows.sort(function (a, b) { var x = a.getAttribute('data-' + key), y = b.getAttribute('data-' + key); if (isNum) return (Number(x) - Number(y)) * dir; return x.localeCompare(y) * dir; }); rows.forEach(function (r) { list.appendChild(r); }); // appendChild moves a row to the end document.querySelectorAll('.sorth').forEach(function (o) { o.classList.remove('on'); }); h.classList.add('on'); }); });

The heading buttons need a little CSS so they look like headings, not buttons (it's in the Full Solution with the rest of the CSS):

CSS
.sorth{all:unset;cursor:pointer;text-transform:inherit;letter-spacing:inherit} .sorth:hover,.sorth.on{color:var(--accent);text-decoration:underline}

Step 5: mark unsaved rows and confirm Delete

Any typing in a form fires its input event, which adds the dirty class from Part 1's CSS. Undo changes is a reset button, and its reset event removes the class. On submit, e.submitter is the button that was pressed; if it is Delete and the admin presses Cancel, preventDefault() stops the form. The name comes from data-name on the form, so an apostrophe in O'Brien can't break the script.

script
// ---- Mark a record "unsaved" as soon as anything in it changes ---- document.querySelectorAll('details.rec form').forEach(function (f) { var d = f.closest('details'); f.addEventListener('input', function () { d.classList.add('dirty'); }); f.addEventListener('reset', function () { d.classList.remove('dirty'); }); // Delete asks first (name read from data-name so quotes in names cannot break it) f.addEventListener('submit', function (e) { if (e.submitter && e.submitter.value === 'delete' && !confirm('Delete ' + f.dataset.name + '? This cannot be undone.')) { e.preventDefault(); return; } d.classList.remove('dirty'); }); });

Step 6: warn before leaving

script
// ---- Warn before leaving the page with unsaved edits ---- window.addEventListener('beforeunload', function (e) { if (document.querySelector('details.dirty')) { e.preventDefault(); e.returnValue = ''; } });
Part 3 is done when Close shuts its row; Expand all opens every row and its words change; clicking # or PC sorts 2 before 10, and clicking again reverses; Name sorts A to Z; Delete asks first, even for O'Brien; the console shows no red errors; and with JavaScript off, Part 2 still works.

Full Solution: week2.html

The complete file, all three parts together. It reads databases/roster.db and databases/district.db in the same folder.

assignments/week2.html
[!] ================================================================ Roster Admin - inline edit form for roster.db One page does everything: list, add, edit (inline), delete. Processing runs at the TOP, before any HTML, then redirects back so a browser refresh never re-submits the form. ================================================================ [/!] [text]dbname=roster.db[/text] [text]dbpath=databases/roster.db[/text] [text]dbdistrict=databases/district.db[/text] [text]thispage=week2.html[/text] [!] ---- sort and show come from the address bar (the toolbar and the redirect). A plain visit to week2.html sends neither, and a variable that was never sent prints its own name. If the value still matches its own name, it was never sent, so blank it. Both sides are url-encoded so a < > ! in the address bar is compared as text, not read as an operator. Fields inside a form need no check: a submitted form always sends them, empty boxes as empty. ---- [/!] [showif [url][sort][/url]=[url][raw][sort][/raw][/url]][text]sort=[/text][/showif] [showif [url][show][/url]=[url][raw][show][/raw][/url]][text]show=[/text][/showif] [text]msgtype=[/text] [!] ---- View settings: only known values get through. Anything else (empty, junk, or a crafted link) becomes the default: first name, active. sort and show are written back into the page, so this also stops a link from putting its own HTML or script into the hidden inputs. ---- [/!] [text]v=first[/text] [showif [url][sort][/url]=last][text]v=last[/text][/showif] [showif [url][sort][/url]=sku][text]v=sku[/text][/showif] [showif [url][sort][/url]=computer][text]v=computer[/text][/showif] [text]sort=[v][/text] [text]v=active[/text] [showif [url][show][/url]=inactive][text]v=inactive[/text][/showif] [showif [url][show][/url]=all][text]v=all[/text][/showif] [text]show=[v][/text] [!] ---- School year dropdown range: 5 back, 5 ahead ---- [/!] [text]thisyear=[date %Y][/text] [text]startyear=[math][thisyear]-5[/math][/text] [text]endyear=[math][thisyear]+5[/math][/text] [!] ---- Add-form memory: if an add fails, refill what was typed ---- [/!] [text]addopen=[/text] [text]note=[/text] [text]a_fname=[/text][text]a_lname=[/text][text]a_uname=[/text][text]a_pword=[/text] [text]a_studentdir=[/text][text]a_computernum=[/text][text]a_email=[/text] [!] ================= PROCESSING ================= [/!] [!] ---- ADD (append) - refuse a duplicate username ---- [/!] [showif [action]=append] [text]dupe=0[/text] [search db=[dbpath]&eqUNAMEdatarq=[url][uname][/url]&max=1][text]dupe=[numfound][/text][/search] [showif [dupe]=0] [append db=[dbpath]&autonumber=sku]FNAME=[url][fname][/url]&LNAME=[url][lname][/url]&KEY=[cart]&UNAME=[url][uname][/url]&PWORD=[url][pword][/url]&SESSION=[url][session][/url]&SCHOOLYEAR=[url][schoolyear][/url]&STATUS=[url][status][/url]&STUDENTDIR=[url][studentdir][/url]&LEVEL=[url][level][/url]&COMPUTERNUM=[url][computernum][/url]&CHATALLOWED=[url][chatallowed][/url]&EMAIL=[url][email][/url]&ADMINACCESS=[url][adminaccess][/url]&r_district=[url][r_district][/url][/append] [closedatabase db=[dbpath]] [redirect [thispage]?sort=[url][sort][/url]&show=[url][show][/url]&msg=added] [/showif] [hideif [dupe]=0] [text]note=Username "[uname]" is already taken. Nothing was added.[/text] [text]msgtype=err[/text] [text]addopen=open[/text] [text]a_fname=[fname][/text][text]a_lname=[lname][/text][text]a_uname=[uname][/text][text]a_pword=[pword][/text] [text]a_studentdir=[studentdir][/text][text]a_computernum=[computernum][/text][text]a_email=[email][/text] [/hideif] [/showif] [!] ---- SAVE (replace) - username must not belong to another record ---- [/!] [showif [action]=replace] [text]dupe=0[/text] [search db=[dbpath]&eqUNAMEdatarq=[url][uname][/url]&neSKUdatarq=[url][skuvar][/url]&max=1][text]dupe=[numfound][/text][/search] [showif [dupe]=0] [replace db=[dbpath]&eqSKUdatarq=[url][skuvar][/url]]FNAME=[url][fname][/url]&LNAME=[url][lname][/url]&UNAME=[url][uname][/url]&PWORD=[url][pword][/url]&SESSION=[url][session][/url]&SCHOOLYEAR=[url][schoolyear][/url]&STATUS=[url][status][/url]&STUDENTDIR=[url][studentdir][/url]&LEVEL=[url][level][/url]&COMPUTERNUM=[url][computernum][/url]&CHATALLOWED=[url][chatallowed][/url]&EMAIL=[url][email][/url]&ADMINACCESS=[url][adminaccess][/url]&r_district=[url][r_district][/url][/replace] [closedatabase db=[dbpath]] [redirect [thispage]?sort=[url][sort][/url]&show=[url][show][/url]&msg=saved] [/showif] [hideif [dupe]=0] [text]note=Username "[uname]" belongs to another student. Record #[skuvar] was NOT saved.[/text] [text]msgtype=err[/text] [/hideif] [/showif] [!] ---- DELETE ---- [/!] [showif [action]=delete] [delete db=[dbpath]&eqSKUdatarq=[url][skuvar][/url]] [closedatabase db=[dbpath]] [redirect [thispage]?sort=[url][sort][/url]&show=[url][show][/url]&msg=deleted] [/showif] [!] ---- Build the search pieces from sort + show ---- [/!] [text]sortq=FNAMEsort=1&LNAMEsort=2[/text] [showif [sort]=last][text]sortq=LNAMEsort=1&FNAMEsort=2[/text][/showif] [showif [sort]=sku][text]sortq=SKUsort=1&SKUtype=num[/text][/showif] [showif [sort]=computer][text]sortq=COMPUTERNUMsort=1&COMPUTERNUMtype=num[/text][/showif] [text]showq=eqSTATUSdatarq=1[/text] [showif [show]=inactive][text]showq=eqSTATUSdatarq=0[/text][/showif] [showif [show]=all][text]showq=neSKUdatarq=findall[/text][/showif] <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Roster Admin</title> <style> :root{ --bg:#f4f6f8; --card:#fff; --ink:#1d2733; --muted:#66727f; --line:#d9dfe5; --accent:#1f7a4d; --accent-soft:#e3f3ea; --warn:#b42318; --warn-soft:#fdecea; --dirty:#f5a524; --dirty-soft:#fff6e5; } *{box-sizing:border-box} body{margin:0;font:15px/1.4 system-ui,-apple-system,Segoe UI,Roboto,sans-serif;background:var(--bg);color:var(--ink)} header{background:var(--accent);color:#fff;padding:18px 24px} header h1{margin:0;font-size:22px} header p{margin:4px 0 0;opacity:.85;font-size:13px} main{max-width:1200px;margin:0 auto;padding:16px} .msg{padding:10px 14px;border-radius:8px;margin-bottom:14px;background:var(--accent-soft);border:1px solid var(--accent)} .msg.err{background:var(--warn-soft);border-color:var(--warn);color:var(--warn)} .toolbar{display:flex;flex-wrap:wrap;gap:10px;align-items:center;margin-bottom:14px} .toolbar form{display:flex;gap:8px;flex-wrap:wrap;align-items:center} .count{margin:0 0 8px;color:var(--muted);font-size:13px} input,select,button{font:inherit} input,select{padding:6px 8px;border:1px solid var(--line);border-radius:6px;background:#fff;width:100%} input:focus,select:focus{outline:2px solid var(--accent);outline-offset:-1px} .toolbar input,.toolbar select{width:auto} button,.btn{padding:7px 14px;border-radius:6px;border:1px solid var(--accent);background:var(--accent);color:#fff;cursor:pointer} button.ghost{background:#fff;color:var(--accent)} button.danger{background:#fff;color:var(--warn);border-color:var(--warn)} button.danger:hover{background:var(--warn);color:#fff} details{background:var(--card);border:1px solid var(--line);border-radius:10px;margin-bottom:8px} details.add{border:2px dashed var(--accent)} details.add > summary{color:var(--accent);font-weight:600} summary{list-style:none;cursor:pointer;padding:10px 14px;display:grid;grid-template-columns:50px 1.4fr 1fr 1fr 1fr 1fr 70px 80px;gap:10px;align-items:center} summary::-webkit-details-marker{display:none} details.add > summary{display:block} summary .sku{color:var(--muted);font-size:13px} summary .name{font-weight:600} summary .small{color:var(--muted);font-size:13px} .badge{display:inline-block;padding:2px 8px;border-radius:99px;font-size:12px;background:var(--accent-soft);color:var(--accent);text-align:center} .badge.off{background:#eceff2;color:var(--muted)} details.inactive summary .name{color:var(--muted);text-decoration:line-through} details.dirty{border-color:var(--dirty);background:var(--dirty-soft)} details.dirty summary .name::after{content:" (unsaved)";color:var(--dirty);font-weight:400;font-size:12px} .listhead{display:grid;grid-template-columns:50px 1.4fr 1fr 1fr 1fr 1fr 70px 80px;gap:10px;padding:0 15px 6px;font-size:12px;text-transform:uppercase;letter-spacing:.04em;color:var(--muted)} .fields{padding:4px 14px 14px;border-top:1px solid var(--line)} .grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:10px 14px;margin-top:10px} fieldset{border:1px solid var(--line);border-radius:8px;padding:8px 10px 10px;margin:0} legend{font-size:12px;font-weight:600;text-transform:uppercase;color:var(--muted);padding:0 4px} label{display:block;font-size:12px;color:var(--muted);margin-top:6px} label:first-of-type{margin-top:0} .actions{display:flex;gap:8px;justify-content:flex-end;margin-top:12px;align-items:center} .actions .key{margin-right:auto;font-size:12px;color:var(--muted)} .sorth{all:unset;cursor:pointer;text-transform:inherit;letter-spacing:inherit} .sorth:hover,.sorth.on{color:var(--accent);text-decoration:underline} .empty{padding:30px;text-align:center;color:var(--muted)} @media (max-width:760px){ .listhead{display:none} summary{grid-template-columns:40px 1fr auto} summary .hidesm{display:none} } </style> </head> <body> <header> <h1>Roster Admin</h1> <p>[dbname] &middot; click a student to edit, then Save. Changes are not kept until you press Save.</p> </header> <main> [!] ---- Messages come back as fixed codes, never as page text from the URL ---- [/!] [showif [url][msg][/url]=added][text]note=Student added.[/text][/showif] [showif [url][msg][/url]=saved][text]note=Changes saved.[/text][/showif] [showif [url][msg][/url]=deleted][text]note=Student deleted.[/text][/showif] [showif [note]!]<div class="msg[showif [msgtype]=err] err[/showif]">[note]</div>[/showif] [!] ================= ADD NEW STUDENT ================= [/!] <details class="add" [addopen]> <summary>+ Add a new student</summary> <form class="fields" method="post" action="[thispage]"> <input type="hidden" name="sort" value="[sort]"> <input type="hidden" name="show" value="[show]"> <div class="grid"> <fieldset><legend>Name</legend> <label>First name<input name="fname" required value="[a_fname]"></label> <label>Last name<input name="lname" required value="[a_lname]"></label> </fieldset> <fieldset><legend>Login</legend> <label>Username<input name="uname" required autocomplete="off" value="[a_uname]"></label> <label>Password<input name="pword" required autocomplete="off" value="[a_pword]"></label> <label>Email<input type="email" name="email" value="[a_email]"></label> </fieldset> <fieldset><legend>Class</legend> <label>Session<select name="session"><option value="1">AM</option><option value="0">PM</option></select></label> <label>School year<select name="schoolyear"> [loop start=[startyear]&end=[endyear]]<option value="[index]"[showif [index]=[thisyear]] selected[/showif]>[index]</option>[/loop] </select></label> <label>Level<select name="level"> <option value="1">1st Year</option><option value="2">2nd Year</option><option value="3">Teacher</option><option value="4">Admin</option><option value="5">Operator</option> </select></label> <label>Computer #<input type="number" name="computernum" min="0" value="[a_computernum]"></label> </fieldset> <fieldset><legend>Account</legend> <label>Status<select name="status"><option value="1">Active</option><option value="0">Inactive</option></select></label> <label>Chat allowed<select name="chatallowed"><option value="1">Yes</option><option value="0">No</option></select></label> <label>Admin access<select name="adminaccess"><option value="0">Student</option><option value="1">Admin</option></select></label> <label>District<select name="r_district" required> <option value="">Choose a district</option> [search db=[dbdistrict]&neSKUdatarq=findall&districtsort=1][founditems]<option value="[sku]">[district]</option>[/founditems][/search] </select></label> </fieldset> <fieldset><legend>Folder</legend> <label>Student directory<input name="studentdir" placeholder="/citi/coding/2026/1/xx/" value="[a_studentdir]"></label> </fieldset> </div> <div class="actions"> <button type="reset" class="ghost">Clear</button> <button type="submit" name="action" value="append">Add student</button> </div> </form> </details> [!] ================= TOOLBAR ================= [/!] <div class="toolbar"> <form method="get" action="[thispage]"> <label class="small" style="margin:0">Show <select name="show" onchange="this.form.submit()"> <option value="active"[showif [show]=active] selected[/showif]>Active</option> <option value="inactive"[showif [show]=inactive] selected[/showif]>Inactive</option> <option value="all"[showif [show]=all] selected[/showif]>All</option> </select> </label> <label class="small" style="margin:0">Sort <select name="sort" onchange="this.form.submit()"> <option value="first"[showif [sort]=first] selected[/showif]>First name</option> <option value="last"[showif [sort]=last] selected[/showif]>Last name</option> <option value="sku"[showif [sort]=sku] selected[/showif]>Record #</option> <option value="computer"[showif [sort]=computer] selected[/showif]>Computer #</option> </select> </label> </form> <button type="button" class="ghost" id="expand">Expand all</button> </div> [!] ================= RECORD LIST (one form per student) ================= [/!] [search db=[dbpath]&[showq]&[sortq]] <p class="count">[numfound] student[showif [numfound]!1]s[/showif]</p> <div class="listhead"><button type="button" class="sorth" data-key="sku" data-type="num">#</button><button type="button" class="sorth" data-key="first">Name</button><span>Username</span><span>Level</span><span>Session</span><span>District</span><button type="button" class="sorth" data-key="pc" data-type="num">PC</button><span>Status</span></div> <div id="list"> [founditems] <details class="rec[showif [status]=0] inactive[/showif]" data-sku="[sku]" data-first="[fname] [lname]" data-pc="[computernum]"> <summary> <span class="sku">#[sku]</span> <span class="name">[fname] [lname]</span> <span class="small hidesm">[uname]</span> <span class="small hidesm">[showif [level]=1]1st Year[/showif][showif [level]=2]2nd Year[/showif][showif [level]=3]Teacher[/showif][showif [level]=4]Admin[/showif][showif [level]=5]Operator[/showif]</span> <span class="small hidesm">[showif [session]=1]AM[/showif][showif [session]=0]PM[/showif]</span> <span class="small hidesm">[lookup db=[dbdistrict]&lookInField=sku&value=[r_district]&returnField=district&notFound=Unknown]</span> <span class="small hidesm">[computernum]</span> <span>[showif [status]=1]<span class="badge">Active</span>[/showif][showif [status]=0]<span class="badge off">Inactive</span>[/showif]</span> </summary> <form class="fields" method="post" action="[thispage]" data-name="[fname] [lname]"> <input type="hidden" name="skuvar" value="[sku]"> <input type="hidden" name="sort" value="[sort]"> <input type="hidden" name="show" value="[show]"> <div class="grid"> <fieldset><legend>Name</legend> <label>First name<input name="fname" required value="[fname]"></label> <label>Last name<input name="lname" required value="[lname]"></label> </fieldset> <fieldset><legend>Login</legend> <label>Username<input name="uname" required autocomplete="off" value="[uname]"></label> <label>Password<input name="pword" required autocomplete="off" value="[pword]"></label> <label>Email<input type="email" name="email" value="[email]"></label> </fieldset> <fieldset><legend>Class</legend> <label>Session<select name="session"> <option value="1"[showif [session]=1] selected[/showif]>AM</option> <option value="0"[showif [session]=0] selected[/showif]>PM</option> </select></label> <label>School year<select name="schoolyear"> [text]rowyear=[schoolyear][/text] [loop start=[startyear]&end=[endyear]]<option value="[index]"[showif [index]=[rowyear]] selected[/showif]>[index]</option>[/loop] </select></label> <label>Level<select name="level"> <option value="1"[showif [level]=1] selected[/showif]>1st Year</option> <option value="2"[showif [level]=2] selected[/showif]>2nd Year</option> <option value="3"[showif [level]=3] selected[/showif]>Teacher</option> <option value="4"[showif [level]=4] selected[/showif]>Admin</option> <option value="5"[showif [level]=5] selected[/showif]>Operator</option> </select></label> <label>Computer #<input type="number" name="computernum" min="0" value="[computernum]"></label> </fieldset> <fieldset><legend>Account</legend> <label>Status<select name="status"> <option value="1"[showif [status]=1] selected[/showif]>Active</option> <option value="0"[showif [status]=0] selected[/showif]>Inactive</option> </select></label> <label>Chat allowed<select name="chatallowed"> <option value="1"[showif [chatallowed]=1] selected[/showif]>Yes</option> <option value="0"[showif [chatallowed]=0] selected[/showif]>No</option> </select></label> <label>Admin access<select name="adminaccess"> <option value="0"[showif [adminaccess]=0] selected[/showif]>Student</option> <option value="1"[showif [adminaccess]=1] selected[/showif]>Admin</option> </select></label> [text]rowdist=[r_district][/text] <label>District<select name="r_district" required> [search db=[dbdistrict]&neSKUdatarq=findall&districtsort=1][founditems]<option value="[sku]"[showif [sku]=[rowdist]] selected[/showif]>[district]</option>[/founditems][/search] </select></label> </fieldset> <fieldset><legend>Folder</legend> <label>Student directory<input name="studentdir" value="[studentdir]"></label> </fieldset> </div> <div class="actions"> <span class="key">Key: [key]</span> <button type="submit" name="action" value="delete" class="danger" formnovalidate>Delete</button> <button type="reset" class="ghost">Undo changes</button> <button type="submit" name="action" value="replace">Save</button> <button type="button" class="ghost close">Close</button> </div> </form> </details> [/founditems] </div> [showif [numfound]=0]<div class="empty">No students match this view.</div>[/showif] [/search] </main> <script> var recs = document.querySelectorAll('details.rec'); // ---- Simple collapse: the Close button shuts its own row ---- document.querySelectorAll('details.rec .close').forEach(function (b) { b.addEventListener('click', function () { b.closest('details').open = false; }); }); // ---- Expand / collapse all ---- var expand = document.getElementById('expand'); expand.addEventListener('click', function () { var open = expand.textContent === 'Expand all'; recs.forEach(function (d) { d.open = open; }); expand.textContent = open ? 'Collapse all' : 'Expand all'; }); // ---- Mark a record "unsaved" as soon as anything in it changes ---- document.querySelectorAll('details.rec form').forEach(function (f) { var d = f.closest('details'); f.addEventListener('input', function () { d.classList.add('dirty'); }); f.addEventListener('reset', function () { d.classList.remove('dirty'); }); // Delete asks first (name read from data-name so quotes in names cannot break it) f.addEventListener('submit', function (e) { if (e.submitter && e.submitter.value === 'delete' && !confirm('Delete ' + f.dataset.name + '? This cannot be undone.')) { e.preventDefault(); return; } d.classList.remove('dirty'); }); }); // ---- Sort the list in the browser: click a column header ---- var list = document.getElementById('list'); var lastKey = '', dir = 1; document.querySelectorAll('.sorth').forEach(function (h) { h.addEventListener('click', function () { var key = h.dataset.key; var isNum = h.dataset.type === 'num'; dir = (key === lastKey) ? -dir : 1; // same header again = reverse lastKey = key; var rows = Array.from(list.querySelectorAll('details.rec')); rows.sort(function (a, b) { var x = a.getAttribute('data-' + key), y = b.getAttribute('data-' + key); if (isNum) return (Number(x) - Number(y)) * dir; return x.localeCompare(y) * dir; }); rows.forEach(function (r) { list.appendChild(r); }); // appendChild moves a row to the end document.querySelectorAll('.sorth').forEach(function (o) { o.classList.remove('on'); }); h.classList.add('on'); }); }); // ---- Warn before leaving the page with unsaved edits ---- window.addEventListener('beforeunload', function (e) { if (document.querySelector('details.dirty')) { e.preventDefault(); e.returnValue = ''; } }); </script> </body> </html> [closedatabase db=[dbpath]] [closedatabase db=[dbdistrict]]

Fix It: if yours doesn't work

What you seeUsual cause
A box or message shows its own name, like [sort]It was never sent: an address-bar value not blanked at the top (Part 2, Step 2), a field missing from the form, or an unchecked checkbox
O'Brien & Sons saves as O'BrienA value in append or replace is not inside [url]
Refresh adds the student againNo redirect after the append
Saving changes the school yearThe year loop compares to this year, not rowyear
Every district dropdown opens on the same districtrowdist not saved before the inner search
Saving blanks the districtThe select is not named r_district
District shows Unknown for everyoneLookup typo: it takes value=, and the fields are sku and district
Computer # sorts 10 before 2Missing COMPUTERNUMtype=num (WebDNA) or data-type="num" (JavaScript)
Every record changes at once, or noneHidden skuvar missing or misnamed
Changes don't show upNo [closedatabase] at the end
Clicking a heading does nothingRows aren't inside <div id="list">, or a data- attribute is missing
Close submits the formThe button is missing type="button"
The script breaks or prints oddlySquare brackets in the script were read as WebDNA