Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Disable javascript validation

Posted on 2009-03-30
1
Medium Priority
?
397 Views
Last Modified: 2012-05-06
Hi, i have this code that validates form fields but i would like to disable some validation fields.
Ok so here is how it works the filed *RUC/C.I: requires for user to insert 10 or 12 digits and the field *Mobile: requires for user to insert a number with 9 digits so the thing is that by default the Country is ECUADOR  but if user chooses other country it should not validate those to fields  *RUC/C.I: and *Mobile: how can i do that?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="JavaScript">
 
function checkFields() {
 
missinginfo = "";
 
    if(/^\d{10}$|^\d{13}$/.test(document.myform.ruci.value)) {
        if(document.myform.ruci.value.length == 13) {
            if(document.myform.empr.value == "")
                missinginfo += "\n     -  Empresa/Responsable";
        }
    }
    else
        missinginfo += "\n     -  RUC/C.I";
 
 
function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		  // alert("test")
		   return false
		}
 
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		 //  alert("test")
		   return false
		}
 
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   // alert("test")
		    return false
		}
 
		 if (str.indexOf(at,(lat+1))!=-1){
		   // alert("test")
		    return false
		 }
 
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   // alert("test")
		    return false
		 }
 
		 if (str.indexOf(dot,(lat+2))==-1){
		   // alert("test")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		  //  alert("test")
		    return false
		 }
return true					
	}
 
if (echeck(document.myform.email_from.value)==false){
		
missinginfo += "\n     -  Email";
}
else {
  
  if (document.myform.email_from.value == "") {
 
missinginfo += "\n     -  Email";
 
  }
}
 
var regex = /^(08|09)[0-9]{7}/
if(!regex.test(document.myform.celular.value)) {
 
missinginfo += "\n     -  Celular";
 
}
 
 
 
if (document.myform.telefono.value == "") {
 
missinginfo += "\n     -  Telefono";
 
}
 
 
 
if (document.myform.direccion.value == "") {
 
missinginfo += "\n     -  Direccion";
 
}
 
if (document.myform.pais.value == "-") {
 
missinginfo += "\n     -  Pais";
 
}
 
if (missinginfo != "") {
 
missinginfo ="_________________________________________________________\n" +
 
"Los datos de los siguientes campos no han sido llenados correctamente:\n" +
 
missinginfo + "\n_______________________________" +
 
"\nPor favor llenelos y vuelva a intentarlo";
 
alert(missinginfo);
 
 
 
return false;
 
}
 
else {
  if (checkCreditCard (document.getElementById('CardNumber').value,document.getElementById('CardType').value)) {
return true
  } 
  else {alert (ccErrors[ccErrorNo]);
  return false
  };
 
 
 
 
};
 
}
 
 
function ShowHide()
{
 
    if(/^\d{10}$|^\d{13}$/.test(document.myform.ruci.value)) {
        if(document.myform.ruci.value.length == 13) {
            document.getElementById("td_empresa").style.display="";
        }
        else if(document.getElementById("td_empresa").style.display=="")
            document.getElementById("td_empresa").style.display="none";
    }
    else if(document.getElementById("td_empresa").style.display=="")
            document.getElementById("td_empresa").style.display="none";
 
}
 
 
</script>
</head>
 
<body>
<form id="myform" name="myform" method="post" action="" onSubmit="return checkFields();">
 
<table width="100%" border="0" align="right" id="table68">
  <tbody>
    <tr>
      <td align="right" valign="top" class="contact_info"><strong><span class="texto-rojo">*</span>RUC/C.I:</strong></td>
      <td width="600"><input name="ruci" title="Ingrese 10 dígitos  para cedula o 13 para RUC (sin guion)" type="text" class="cajas-form" value="" id="ruci" onkeyup="ShowHide();" onblue="ShowHide();" /></td>
    </tr>
    <tr id="td_empresa" style="display:none;">
      <td align="right" valign="top" class="contact_info"><strong><span class="texto-rojo">*</span>Company/Responsible:</strong></td>
      <td><input name="empr" title="Ingrese nombre de Empresa o Responsable (campo obligatorio si ingresado RUC)" type="text" class="cajas-form" value="" id="empr" /></td>
    </tr>
    <tr>
      <td align="right" valign="top" class="contact_info"><strong> Code:</strong></td>
      <td width="205"><input name="clave" title="Ingrese Clave de Descuento (clave enviada por email en cada promoción disponible SOLO PARA CLIENTES)" type="text" class="cajas-form" value="" /></td>
    </tr>
    <tr>
      <td align="right" valign="top" class="contact_info"><strong><span class="texto-rojo">*</span>Email:</strong></td>
      <td><input name="email_from" title="Ingrese Correo Electrónico (ingrese un email valido para recibir promociones, notificaciones y  estados de su orden)"  type="text" class="cajas-form" value="" /></td>
    </tr>
    <tr>
      <td align="right" valign="top" class="contact_info"><strong><span class="texto-rojo">*</span>Mobile:</strong></td>
      <td><input name="celular" title="Ingrese número Celular (para notificaciónes y estados de su orden)" type="text" class="cajas-form" value="" id="celular" /></td>
    </tr>
    <tr>
      <td align="right" valign="top" class="contact_info"><strong><span class="texto-rojo">*</span>Phone:</strong></td>
      <td><input name="telefono" title="Ingrese número local (para notificaciones y estados de su orden)" type="text" class="cajas-form" value="" /></td>
    </tr>
    <tr>
      <td align="right" valign="top" class="contact_info"><strong><span class="texto-rojo">*</span>Address:</strong></td>
      <td ><label>
        <textarea name="direccion" title="Ingrese dirección (de oficina o casa)" cols="45" rows="5" class="cajas-form" id="direccion"></textarea>
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top" class="contact_info"><strong><span class="texto-rojo">*</span>Pais:</strong></td>
      <td><select name="pais" title="Seleccione el país en el que se encuentra actualmente" style=" font-family: Tahoma; font-size: 10px; color: #666666; border: 1px solid #A2A19D; background-color: #fffefb; width: 140px; font-weight: bold;">
        <option value="-">[Elija] </option>
        <option value="AL">Albania </option>
        <option value="DE">Alemania </option>
        <option value="AO">Angola </option>
        <option value="SA">Arabia Saudita </option>
        <option value="DZ">Argelia </option>
        <option value="AR">Argentina </option>
        <option value="AU">Australia </option>
        <option value="AT">Austria </option>
        <option value="BE">Belgica </option>
        <option value="BO">Bolivia </option>
        <option value="BR">Brasil </option>
        <option value="BG">Bulgaria </option>
        <option value="KH">Cambodia </option>
        <option value="CA">Canada </option>
        <option value="CL">Chile </option>
        <option value="CN">China </option>
        <option value="CO">Colombia </option>
        <option value="CR">Costa Rica </option>
        <option value="HR">Croacia </option>
        <option value="CU">Cuba </option>
        <option value="DK">Dinamarca </option>
        <option value="EC" selected="selected"> Ecuador </option>
        <option value="EG">Egipto </option>
        <option value="SV">El Salvador </option>
        <option value="SK"> Eslovaquia </option>
        <option value="ES">Espana </option>
        <option value="US">Estados Unidos </option>
        <option value="ET">Etiopia </option>
        <option value="PH">Filipinas </option>
        <option value="FI">Finlandia </option>
        <option value="FR">Francia </option>
        <option value="GE">Georgia </option>
        <option value="GB">Gran Bretana </option>
        <option value="GR">Grecia </option>
        <option value="GT">Guatemala </option>
        <option value="HT">Haiti </option>
        <option value="NL">Holanda </option>
        <option value="HN">Honduras </option>
        <option value="HU">Hungria </option>
        <option value="IN">India </option>
        <option value="ID">Indonesia </option>
        <option value="IQ">Irak </option>
        <option value="IR">Iran </option>
        <option value="IE">Irlanda </option>
        <option value="IS">Islandia </option>
        <option value="IL">Israel </option>
        <option value="IT">Italia </option>
        <option value="JM">Jamaica </option>
        <option value="JP">Japon </option>
        <option value="JO">Jordania </option>
        <option value="KP">Korea del Norte </option>
        <option value="KR">Korea del Sur </option>
        <option value="KW">Kuwait </option>
        <option value="LB">Libano </option>
        <option value="LR">Liberia </option>
        <option value="LT">Lituania </option>
        <option value="LU"> Luxemburgo </option>
        <option value="MO">Macao </option>
        <option value="MT">Malta </option>
        <option value="MA">Marruecos </option>
        <option value="MX">Mexico </option>
        <option value="MN">Mongolia </option>
        <option value="MZ"> Mozambique </option>
        <option value="NP">Nepal </option>
        <option value="NI">Nicaragua </option>
        <option value="NG">Nigeria </option>
        <option value="NO">Noruega </option>
        <option value="NZ">Nueva Zelandia </option>
        <option value="PK">Pakistan </option>
        <option value="PA">Panama </option>
        <option value="PY">Paraguay </option>
        <option value="PE">Peru </option>
        <option value="PL">Polonia </option>
        <option value="PT">Portugal </option>
        <option value="PR">Puerto Rico </option>
        <option value="UK">Reino Unido </option>
        <option value="CZ">Republica Checa </option>
        <option value="DO">Republica Dominicana </option>
        <option value="RO">Rumania </option>
        <option value="RU">Rusia </option>
        <option value="SN">Senegal </option>
        <option value="SY">Siria </option>
        <option value="SI">Slovenia </option>
        <option value="SO">Somalia </option>
        <option value="ZA">Sudafrica </option>
        <option value="SE">Suecia </option>
        <option value="CH">Suiza </option>
        <option value="SR">Surinam </option>
        <option value="TH">Tailandia </option>
        <option value="TW">Taiwan, China </option>
        <option value="TR">Turquia </option>
        <option value="UG">Uganda </option>
        <option value="UY">Uruguay </option>
        <option value="VE">Venezuela </option>
        <option value="VN">Vietnam </option>
        <option value="YE">Yemen </option>
        <option value="YU"> Yugoslavia </option>
      </select></td>
    </tr>
    <tr>
      <td align="right" valign="top" class="contact_info">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td align="right" valign="top" class="contact_info">&nbsp;</td>
      <td><label>
        <input type="submit" name="button" id="button" value="Submit" />
      </label></td>
    </tr>
  </tbody>
</table>
</form>
</body>
</html>

Open in new window

0
Comment
Question by:jd_18286
1 Comment
 
LVL 12

Accepted Solution

by:
alien109 earned 2000 total points
ID: 24021317
You need to wrap the two validation checks in a conditional statement that checks to see if Ecuador is selected.

The two conditions that need to be wrapped appear below:

if(document.myform.pais.value != "EC") {
      if(/^\d{10}$|^\d{13}$/.test(document.myform.ruci.value)) {
            if(document.myform.ruci.value.length == 13) {
                  if(document.myform.empr.value == "")
                        missinginfo += "\n     -  Empresa/Responsable";
            }
      }
      else
            missinginfo += "\n     -  RUC/C.I";
}

if(document.myform.pais.value != "EC") {
      var regex = /^(08|09)[0-9]{7}/
      if(!regex.test(document.myform.celular.value)) {
            missinginfo += "\n     -  Celular";
      }
}
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question