|
Hi
I have written a sexy little _javascript_ form
validator
it relies on custom attribs within the form fields
however
<input type="text" name="textbox"
Validate="txt">
and based on the value of
document.forms['theform'][x].Validate
a validation routine is run
however Mozilla doesnt seem to be able to
read the value of the custom attrib
anyone know why?
here is my code
---------------------------
<script
language="_javascript_">
function loopval(formname)
{
// set up form variables var re = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; theForm = document.forms[''+formname+'']; looplen = theForm.length; var errorInd =0; var errorMsg ='The following errors were found\n'; alert(looplen); //loop over length of form for(i=0 ; i<looplen ; i++) { alert(i); //setup looping vars switchObj = theForm[i].validate; formVal = theForm[i].value; fieldName = theForm[i].name; // NETSCAPE CHECK alert(theForm[i].validate.value); //switch statement switch(switchObj) { case 'txt' : if (!isNaN(formVal)) { errorInd=1; errorMsg =errorMsg + 'The field '+fieldName+' must contain alphanumerics\n'; }; break; case 'nmb' : if (isNaN(formVal)) { errorInd=1; errorMsg = errorMsg +'The field '+fieldName+' must contain only numbers\n'; }; break; case 'email' : if(!formVal.match(re)) { errorInd=1; errorMsg = errorMsg +'The field '+fieldName+' must contain a syntactically valid Email address\n'; }; break; } } if (errorInd ==1) { alert(errorMsg); } else {theForm.submit(); } } </script>
<form name="test" method="post" action=""> <input type="text" name="txtbox"
validate="txt">
<input type="text" name="txtbox" validate="nmb"> <input type="text" name="txtbox" validate="email"> <input type="text" name="txtbox" validate="that"> <input type="text" name="txtbox" validate="other"> <input type="button" > </form>
|\--------------------/|
Matt Horn Web Applications Developer Ph:+2782 424 3751 W: http://www.matt-horn.org E:[EMAIL PROTECTED] |\--------------------/| |
- RE: [ cf-dev ] OT : Custom form attribs + Netsca... Matt Horn
- RE: [ cf-dev ] OT : Custom form attribs + N... Robertson-Ravo, Neil (RX)
- RE: [ cf-dev ] OT : Custom form attribs + N... Robertson-Ravo, Neil (RX)
- RE: [ cf-dev ] OT : Custom form attribs + N... Robertson-Ravo, Neil (RX)
- RE: [ cf-dev ] OT : Custom form attribs + N... Robertson-Ravo, Neil (RX)
- RE: [ cf-dev ] OT : Custom form attribs... Sam Westlake
- Re: [ cf-dev ] OT : Custom form attribs... Matt Horn
- Re: [ cf-dev ] OT : Custom form attribs + N... Matt Horn
- RE: [ cf-dev ] OT : Custom form attribs + N... Robertson-Ravo, Neil (RX)
