Or better (by far):
Code:
var e1 = document.createElement("input");
e1.name = e1.id = "org";
e1.type = "text";
e1.className = "style4";
e1.maxLength = 42;
e1.value = "Test";
e1.onfocus = function() {
if(this.value === this.defaultValue)
this.value = '';
};
e1.size = 19;
Or perhaps (neater in my opinion):
Code:
function buildElement(tag, attrs, children) {
var e = document.createElement(tag);
for(var x in attrs)
if(attrs.hasOwnProperty(x))
e[x] = attrs[x];
if(children)
for(var i = 0, n = children.length; i < n; ++i)
e.appendChild(children);
return e;
}
var e1 = buildElement("input", {
name: "org",
id: "org",
type: "text",
className: "style4",
maxLength: 42,
value: "Organisation",
onfocus: function() {
if(this.value === this.defaultValue)
this.value = '';
},
onblur: function() {
if(!this.value)
this.value = this.defaultValue;
},
size: 19
});
Bookmarks