[UPHPU] JavaScript Question
Brady Mitchell
bradym at ext.usu.edu
Fri Mar 24 16:37:37 MST 2006
I'm trying to adapt the script from
http://www.quirksmode.org/index.html?/js/forms.html to work with all
different kinds of input fields, and I can't get it working with radio
buttons or checkboxes.
The problem is with the writeError function:
function writeError(obj,message)
{
validForm = false;
if (obj.hasError) return;
if (W3CDOM)
{
obj.className += ' error';
obj.onchange = removeError;
var sp = document.createElement('span');
sp.className = 'error';
sp.appendChild(document.createTextNode(message));
obj.parentNode.appendChild(sp);
obj.hasError = sp;
}
else
{
errorstring += obj.name + ': ' + message + '\\n';
obj.hasError = true;
}
if (!firstError)
firstError = obj;
}
When I pass a radio button name, it dies on the line with
"obj.parentNode.appendChild(sp);" and says that parentNode doesn't
exist.
With a checkbox, it does on "if (obj.hasError) return;" and says that
obj has no properties.
Any suggestions on how to get this working with radio buttons and
checkboxes?
Thanks,
Brady
More information about the UPHPU
mailing list