|
What Neil said.
Just tested this in FireFox ... updated the form field to
use "id" as well as "name" attributes, although this isn't necessarily needed.
<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<parseInt(looplen) ; i++) { //alert(i + " is the current loop position"); //setup looping vars switchObj = theForm[i].getAttribute('validate'); formVal = theForm[i].getAttribute('value'); fieldName = theForm[i].getAttribute('name'); // NETSCAPE CHECK alert(theForm[i].getAttribute('validate')); //switch statement switch(switchObj) {
case 'txt' : if (!isNaN(formVal)) { alert("Found an Error"); 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; } alert("Error no is " + errorInd); }
if (errorInd ==1) { alert(errorMsg); } else {theForm.submit(); } } </script> <form name="test" id="test" method="post"
action=""> <input type="text" name="txtbox1" id="txtbox1" validate="txt"> <input type="text" name="txtbox2" id="txtbox2" validate="nmb"> <input type="text" name="txtbox3" id="txtbox3" validate="email"> <input type="text" name="txtbox4" id="txtbox4" validate="that"> <input type="text" name="txtbox5" id="txtbox5" validate="other"> <input type="button" > </form> From: Robertson-Ravo, Neil (RX) [mailto:[EMAIL PROTECTED] Sent: 20 July 2004 14:07 To: '[EMAIL PROTECTED]' Subject: RE: [ cf-dev ] OT : Custom form attribs + Netscape In fact just change
Line 17 to : switchObj =
theForm[i].getAttribute('Validate'); Job
done.. From: Matt Horn
[mailto:[EMAIL PROTECTED] 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)
{ </script>
<input type="text"
name="txtbox" validate="txt"> </form> |\--------------------/| This e-mail is from Reed Exhibitions (Oriel House, 26 The Quadrant, Richmond, Surrey, TW9 1DL, United Kingdom), a division of Reed Business, Registered in England, Number 678540. It contains information which is confidential and may also be privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any form of distribution, copying or use of this communication or the information in it is strictly prohibited and may be unlawful. If you have received this communication in error please return it to the sender or call our switchboard on +44 (0) 20 89107910. The opinions expressed within this communication are not necessarily those expressed by Reed Exhibitions. Visit our website at http://www.reedexpo.com |
- [ cf-dev ] OT : Custom form attribs + Netscape 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)
