sweet thanks :D
 
 
----- Original Message -----
Sent: Tuesday, July 20, 2004 3:06 PM
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]
Sent: 20 July 2004 13:41
To: [EMAIL PROTECTED]
Subject: [ cf-dev ] OT : Custom form attribs + Netscape

 

 

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]
|\--------------------/|

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

Reply via email to