Formvalidator from the iframe.

Posted by basit74 on Stack Overflow See other posts from Stack Overflow or by basit74
Published on 2010-05-21T08:30:01Z Indexed on 2010/05/21 8:40 UTC
Read the original article Hit count: 270

Filed under:

Hello I have a following formvalidatior function in my document.

function formValidator(formid) {

  var form = cic.$(formid);

  if(!form) return ('');

  var errors = [];
    var len = form.elements.length;

  for(var elementIdx = 0; elementIdx < len; elementIdx++) {

    var element = form.elements[elementIdx];

    if(!element && !element.getAttribute('validationtype')) return ('');

    switch (element.getAttribute('validationtype')) {

      case 'text'    :  if(cic.getValue(element).strip() == "") errors.push(element.getAttribute('validationmsg'));
                        break;

      case 'email'   :  if(!cic.isEmail(cic.getValue(element))) errors.push(element.getAttribute('validationmsg'));
                        break;

      case 'numeric' :  if(isNaN(cic.getValue(element).replace(',', '.'))) errors.push(element.getAttribute('validationmsg'));
                        break;         

      case 'confirm' :  if(cic.getValue(cic.$(element.getAttribute('sourcefield'))) !== cic.getValue(element)) errors.push(element.getAttribute('validationmsg'));
                        break;         
    }

  }

  return (errors.length > 0) ? '<li>' + errors.uniq().join("<li>") : '';
}

It works fine, now I have an Iframe in my document, and that I frame contains the form to validate. What will be the best practice to change this function in such a way that it can validate document forms and iframe from simeltaniously.

Thanks

© Stack Overflow or respective owner

Related posts about JavaScript