More useful JS: Prototype revisited

OK, for those of you watching from the sidelines, remember when we talked about the Prototype framework, and I said it could be done slicker? I am now correcting those little errors.

First of all, I was not using enough parts of Prototype, and so I was doing unnecessary stuff, and also, I was leaving empty `` tags in the DOM, not removing them like I should.

/* Shows the order form, and hides the button. */
function turnOnForm()
{
Element.toggle(“orderform”, “enablerButton”);
}
/**
* Returns false if listed fields are not filled out.
*/
function checkform(frm)
{
var labeltext = “Hey!“;
var fields = new Array(“nameid”,
“emailid”, “addressid”,
“zipid”, “cityid”, “phoneid”);
var we_have_an_error = false;

/* Remove the removables */
var lbls = document.getElementsByClassName(“removable”);
for (i=0; i {
Element.remove(lbls[i]);
}

for (i=0; i {
if (!Field.present(fields[i]))
{
new Insertion.After(fields[i], labeltext);
we_have_an_error = true;
}
}

return (!we_have_an_error);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>