Skip to main content
se eliminaron 1488 caracteres en el cuerpo
Origen Enlace
Marcos Martínez
  • 2.3k
  • 1
  • 13
  • 21
function comprobarClave(){ 
  let bl = document.getElementById('bl').value;
  let bl2 = document.getElementById('bl2').value;
  if (bl != bl2){
     alert("Las dos BL Diferentes, no se submiteará el form") 
     return false;
  }else{
      alert("Las dos BL iguales, se submiteará el form") 
      return true;
   }
}
<form action="" method="post" onsubmit = "return comprobarClave();" autocomplete="off" name="caso"><table width="1151" height="155" border="0" cellspacing="0">
      <tr>
        <td>BL/BOOKING:</td>
        <td>&nbsp;</td>
        <td><label for="bl"></label><table>
          <input type="text" name="bl" id="bl" required="required" /></td><tr>
        <td>&nbsp;</td>
        <td>BL/BOOKING:</td>
        <td>&nbsp;</td>
        <td><label for="fech">
          <input type="text" name="bl2" id="bl2" required="required" />
        </label></td>
        <td>&nbsp;</td>
        <td>Fecha:</td>
       <td><label <td>&nbsp;<for="bl"></td>label>
        <td><label for="fech">
          <input type="date"type="text" name="fech"name="bl" id="fech"id="bl" required="required" />
        </label><></td>
        </tr>
      <tr>
        <td>Nombre del cliente:</td>
        <td>&nbsp;</td>
        <td><input type="text" name="textfield2" id="nom_cli" /></td>
        <td>&nbsp;<<td>BL/td>
        <td>Codigo del clienteBOOKING:</td>
        <td>&nbsp;</td>
        <td><input type="text" name="cod_cli" id="cod_cli" required="required"/></td>
        <td>&nbsp;</td>
        <td>Origen:</td>
       <td><label <td>&nbsp;</td>for="fech">
        <td><label for="Destino">
          <input type="text" name="fech2"name="bl2" id="fech2"id="bl2" required="required" />
        </label></td>
      </tr>
      <tr>
        <td>Cantidad de items/cont:</td>
        <td>&nbsp;</td>
        <td><label for="cant"></label>
          <input type="number" name="cant" id="cant" min="1"/>      <label for="textfield2"></label></td>
        <td>&nbsp;</td>
        <td>Almacenamiento:</td>
        <td>&nbsp;</td>
        <td><label for="alm"></label>
          <input type="date" name="alm" id="alm" /></td>
        <td>&nbsp;</td>
        <td>Retención:</td>
        <td>&nbsp;</td>
        <td><label for="ret"></label>
          <input type="date" name="ret" id="ret" /></td>
        </tr>
      <tr>
      </table>
      <p>&nbsp;</p>
      <p>
        <input type="submit" class="button" name="send"  value="Guardar" />
      </p>
  </form>
function comprobarClave(){ 
  let bl = document.getElementById('bl').value;
  let bl2 = document.getElementById('bl2').value;
  if (bl != bl2){
     alert("Las dos BL Diferentes, no se submiteará el form") 
     return false;
  }else{
      alert("Las dos BL iguales, se submiteará el form") 
      return true;
   }
}
<form action="" method="post" onsubmit = "return comprobarClave();" autocomplete="off" name="caso"><table width="1151" height="155" border="0" cellspacing="0">
      <tr>
        <td>BL/BOOKING:</td>
        <td>&nbsp;</td>
        <td><label for="bl"></label>
          <input type="text" name="bl" id="bl" required="required" /></td>
        <td>&nbsp;</td>
        <td>BL/BOOKING:</td>
        <td>&nbsp;</td>
        <td><label for="fech">
          <input type="text" name="bl2" id="bl2" required="required" />
        </label></td>
        <td>&nbsp;</td>
        <td>Fecha:</td>
        <td>&nbsp;</td>
        <td><label for="fech">
          <input type="date" name="fech" id="fech" required="required" />
        </label></td>
        </tr>
      <tr>
        <td>Nombre del cliente:</td>
        <td>&nbsp;</td>
        <td><input type="text" name="textfield2" id="nom_cli" /></td>
        <td>&nbsp;</td>
        <td>Codigo del cliente:</td>
        <td>&nbsp;</td>
        <td><input type="text" name="cod_cli" id="cod_cli" required="required"/></td>
        <td>&nbsp;</td>
        <td>Origen:</td>
        <td>&nbsp;</td>
        <td><label for="Destino">
          <input type="text" name="fech2" id="fech2" required="required" />
        </label></td>
      </tr>
      <tr>
        <td>Cantidad de items/cont:</td>
        <td>&nbsp;</td>
        <td><label for="cant"></label>
          <input type="number" name="cant" id="cant" min="1"/>      <label for="textfield2"></label></td>
        <td>&nbsp;</td>
        <td>Almacenamiento:</td>
        <td>&nbsp;</td>
        <td><label for="alm"></label>
          <input type="date" name="alm" id="alm" /></td>
        <td>&nbsp;</td>
        <td>Retención:</td>
        <td>&nbsp;</td>
        <td><label for="ret"></label>
          <input type="date" name="ret" id="ret" /></td>
        </tr>
      
      </table>
      <p>&nbsp;</p>
      <p>
        <input type="submit" class="button" name="send"  value="Guardar" />
      </p>
  </form>
function comprobarClave(){ 
  let bl = document.getElementById('bl').value;
  let bl2 = document.getElementById('bl2').value;
  if (bl != bl2){
     alert("Las dos BL Diferentes, no se submiteará el form") 
     return false;
  }else{
      alert("Las dos BL iguales, se submiteará el form") 
      return true;
   }
}
<form action="" method="post" onsubmit = "return comprobarClave();" autocomplete="off" name="caso"><table width="1151" height="155" border="0" cellspacing="0">
      <table>
        <tr>
          <td>BL/BOOKING:</td>
          <td>&nbsp;</td>
          <td><label for="bl"></label>
            <input type="text" name="bl" id="bl" required="required" /></td>
          <td>&nbsp;</td>
          <td>BL/BOOKING:</td>
          <td>&nbsp;</td>
          <td><label for="fech">
            <input type="text" name="bl2" id="bl2" required="required" />
          </label></td>     
        <tr>
      </table>
      <p>
        <input type="submit" class="button" name="send"  value="Guardar" />
      </p>
  </form>
Origen Enlace
Marcos Martínez
  • 2.3k
  • 1
  • 13
  • 21

Puedes utilizar el atributo onsubmit del formulario, colocando una función js que se invocará cuando este sea submiteado al clickear el botón.

La función deberá retornar true o false dependiendo de si quieres submitear o no el formulario.

function comprobarClave(){ 
  let bl = document.getElementById('bl').value;
  let bl2 = document.getElementById('bl2').value;
  if (bl != bl2){
     alert("Las dos BL Diferentes, no se submiteará el form") 
     return false;
  }else{
      alert("Las dos BL iguales, se submiteará el form") 
      return true;
   }
}
<form action="" method="post" onsubmit = "return comprobarClave();" autocomplete="off" name="caso"><table width="1151" height="155" border="0" cellspacing="0">
      <tr>
        <td>BL/BOOKING:</td>
        <td>&nbsp;</td>
        <td><label for="bl"></label>
          <input type="text" name="bl" id="bl" required="required" /></td>
        <td>&nbsp;</td>
        <td>BL/BOOKING:</td>
        <td>&nbsp;</td>
        <td><label for="fech">
          <input type="text" name="bl2" id="bl2" required="required" />
        </label></td>
        <td>&nbsp;</td>
        <td>Fecha:</td>
        <td>&nbsp;</td>
        <td><label for="fech">
          <input type="date" name="fech" id="fech" required="required" />
        </label></td>
        </tr>
      <tr>
        <td>Nombre del cliente:</td>
        <td>&nbsp;</td>
        <td><input type="text" name="textfield2" id="nom_cli" /></td>
        <td>&nbsp;</td>
        <td>Codigo del cliente:</td>
        <td>&nbsp;</td>
        <td><input type="text" name="cod_cli" id="cod_cli" required="required"/></td>
        <td>&nbsp;</td>
        <td>Origen:</td>
        <td>&nbsp;</td>
        <td><label for="Destino">
          <input type="text" name="fech2" id="fech2" required="required" />
        </label></td>
      </tr>
      <tr>
        <td>Cantidad de items/cont:</td>
        <td>&nbsp;</td>
        <td><label for="cant"></label>
          <input type="number" name="cant" id="cant" min="1"/>      <label for="textfield2"></label></td>
        <td>&nbsp;</td>
        <td>Almacenamiento:</td>
        <td>&nbsp;</td>
        <td><label for="alm"></label>
          <input type="date" name="alm" id="alm" /></td>
        <td>&nbsp;</td>
        <td>Retención:</td>
        <td>&nbsp;</td>
        <td><label for="ret"></label>
          <input type="date" name="ret" id="ret" /></td>
        </tr>
      
      </table>
      <p>&nbsp;</p>
      <p>
        <input type="submit" class="button" name="send"  value="Guardar" />
      </p>
  </form>