http://dynamicdrive.com/forums/showp...postcount=1337 — 1.1, 1.2, 1.4, 3.1, 3.2, 5.1, 5.2, 5.3, 5.4, 5.5. In addition, use of the 'with' statement is heavily frowned upon in ECMAScript, since it alters the current namespace unpredictably.
Code:
<!DOCTYPE html "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>MadLibs!</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body {
background-color: white;
color: black;
font-family: sans-serif;
margin: 0.5em;
padding: 0.5em;
}
.madlibs label {
font-size: 60%;
color: red;
}
.madlibs input {
border: 0 none;
font-family: sans-serif;
color: #555;
text-align: center;
border-bottom: 1px dotted #888;
width: 7em;
}
.madlibs label input {
font-size: 166%;
}
.madlibs .submit {
border: 0 none;
color: blue;
background-color: white;
text-decoration: underline;
cursor: pointer;
}
</style>
<script type="text/javascript">
var Functional = {
map: function(f, a) {
for (var i = a.length - 1, r = []; i >= 0; --i)
r[i] = f(a[i], i);
return r;
},
filter: function(f, a) {
if (typeof f === "string")
f = (function(f) { return function(a) { return !!a[f]; }; })(f);
for (var i = 0, r; i < a.length; ++i)
if (f(a[i]))
r.push(a[i]);
return r;
},
reduce: function(f, a, t) {
if (!a.length)
return t;
t = t || a[0];
for (var i = 0, n = a.length; i < n; ++i)
t = f(t, a[i]);
return t;
}
};
var Form = (function(F) {
function getValue(inp, comb) {
if (typeof inp.value !== undefined)
return inp.value;
if (inp.tagName.toLowerCase() === "select")
return inp.options[inp.selectedIndex].value;
return F.reduce(comb || function(a, b) { return a.value + b.value }, F.filter("checked", inp)) || "";
}
function freeze(form) {
F.map(function(el) {
if (el.type && el.type.toLowerCase() === "submit")
el.parentNode.removeChild(el);
else {
var nel = document.createElement("span"),
rmel = el.parentNode.tagName.toLowerCase() === "label" ? el.parentNode : el;
nel.appendChild(document.createTextNode(getValue(el))).parentNode.className = "frozen-input";
rmel.parentNode.replaceChild(nel, rmel);
}
var form = el = nel = null;
}, form.elements);
return form;
}
return {freeze: freeze};
})(Functional);
</script>
</head>
<body>
<form class="madlibs" action="/server/side/equivalent" method="post" onsubmit="Form.freeze(this); return false;">
<div>
<p>One day, while I was <input type="text"> in the <input type="text"> a <input type="text"> <input type="text"> fell through the roof. It immediately jumped on the <input type="text"> and knocked over the <input type="text">. Then it ran out of the door and into the <input type="text"> and <input type="text"> a <input type="text"> off the <input type="text">. It then knocked a glass of <input type="text"> off the coffee table. After <input type="text"> minutes of chasing the <input type="text"> through the house I finally caught it and put it outside. It quickly climbed the nearest <input type="text">.
</p>
<input class="submit" type="submit" value="Freeze">
</div>
</form>
</body>
</html>
Bookmarks