[Javascript] Why won't this work????

BEKIM BACAJ trojani2000 at hotmail.com
Wed Jan 29 14:08:06 CST 2003




Please check the syntax of the following code line(s):

...       if (a.indexOf(arrBadChars[i]) != '-1')

what r'you comparing to? ['-1' -!is not a number it's a text,literal]
skiped to se if:
           a.(...)
is evaluated,an object,  -or else

Anyway checking these could very posibly help,
Regards!



>From: "Cutter (JavaScript)" <javascript at theblades-family.com>
>Reply-To: javascript at LaTech.edu
>To: javascript at LaTech.edu
>Subject: [Javascript] Why won't this work????
>Date: Wed, 29 Jan 2003 14:07:19 -0500
>
>I've created a form validation script, but for some reason it keeps choking 
>after it does the 8th field the second time around. Anyone???
>
>var fieldnames = new Array();
>var Item = new Array();
>fieldnames[0] = (Item =['name','text','Please supply your Name',0,0]);
>fieldnames[1] = (Item = ['title','text','Please supply your Title',0,0]);
>fieldnames[2] = (Item = ['company','text','Please supply your Company 
>name',0,0]);
>fieldnames[3] = (Item = ['address','text','Please supply your 
>Address',0,0]);
>fieldnames[4] = (Item = ['city','text','Please supply your City',0,0]);
>fieldnames[5] = (Item = ['country','select','Please supply your 
>Country',0,0]);
>fieldnames[6] = (Item = ['state_province','select','Please supply your 
>State or province',0,0]);
>fieldnames[7] = (Item = ['zip_or_country_code','text','Please supply your 
>Zip or Country Code',0,0]);
>fieldnames[8] = (Item = ['phone','text','Please supply your Phone 
>number',1,0]);
>fieldnames[9] = (Item = ['fax','text','Please supply your Fax 
>number',1,0]);
>fieldnames[10] = (Item = ['email','text','You must enter a valid Email 
>address',1,1]);
>
>function isEmpty(form, field)
>{
>
>    fn = getField(field);
>    tp = getType(field);
>    result = false;
>        if(tp == 'text')
>    {
>          strValue = "form." + fn + ".value";
>      }
>      if(tp == 'select')
>    {
>          strValue = "form." + fn + ".options[form." + fn + 
>".selectedIndex].value";
>      }
>      if ((eval(strValue) == null) || (eval(strValue) == ''))
>        result = true;
>          return result;
>
>}
>
>function getField(field)
>{
>
>    Item = field;
>    return Item[0];
>
>}
>
>function getType(field)
>{
>
>    Item = field;
>    return Item[1];
>   }
>
>function getError(field)
>{
>
>    Item = field;
>    return Item[2];
>
>}
>
>function blValChar(field)
>{
>
>    Item = field;
>    return Item[3];
>
>}
>
>function blValMail(field)
>{
>
>    Item = field;
>    return Item[4];
>
>}
>
>function showError(field, form)
>{
>
>    alert(getError(field));
>    a = "form." + getField(field);
>    eval(a).focus();
>    if(getType(field) == 'text')
>        eval(a).select();
>
>}
>
>function charCheck(field, form)
>{
>
>    result = true;
>    var arrBadChars = new 
>Array("~","`","!","@","#","$","%","%","^","&","*","(",")","_","=",":",";","'","<",">",".","?","/");
>    strField = "form." + getField(field);
>    a = eval(strField).value;
>      for (i = 0; i < arrBadChars.length; i++)
>    {
>          if (a.indexOf(arrBadChars[i]) != '-1')
>        {
>                      alert('Please do not enter any illegal characters');
>            eval(strField).focus();
>            eval(strField).select();
>            result = false;
>            return result;
>                  }
>          }
>      return result;
>
>}
>
>function chkMail(field, form)
>{
>
>    re= /^\w+([\.-]?\w)*@\w+([\.]?\w+)*(\.\w{2,4})+$/; // RegEx for testing 
>email
>    result = true;
>    strField = "form." + getField(field);
>    strValue = eval(strField).value;
>      if(!re.test(strValue))
>        result = false;
>      return result;
>
>}
>
>function valForm(form)
>{
>
>    for( i = 0; i < fieldnames.length; i++ )
>    {
>          alert("Field " + i + " " + getField(fieldnames[i]));
>              if(isEmpty(form,fieldnames[i]))
>        {
>                  showError(fieldnames[i],form);
>            return false;
>              }
>              if(blValChar(fieldnames[i]))
>        {
>                  if(!charCheck(fieldnames[i], form))
>                return false;
>                      }
>              if(blValMail(fieldnames[i]))
>        {
>                  if(!chkMail(fieldnames[i]))
>                return false;
>              }
>          }
>      return true;
>
>}
>
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript


_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE* 
http://join.msn.com/?page=features/junkmail




More information about the Javascript mailing list