Problem with HTML 5 form in JavaScript

0

I do not understand why the function that believes in java script with this form does not work for me, simplify the code so that the problem can be better understood

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>
    Obligatorio
    </title>
    <link rel="stylesheet" href="./css/Estilo.css">
    <link rel="stylesheet" href="./css/EstilosChico.css"
            media="screen and (max-width: 600px)">
  </head>    
  <body>
<form action="no_existe.html" method="get" id="miformulario">    
<textarea rows="8" cols=80" id="comentarios" placeholder="Ingrese los comentarios" ></textarea>
<script>
          function hizoClick() {
            event.preventDefault();
            var text = document.getElementById("comentarios").value.toUpperCase();
            if (text.indexOf("EXCELENTE") != -1) {
              alert("El campo comentarios contiene Excelente");
            } else {
              document.getElementById("miformulario").submit();
              enviado();
            }
</script>
<script>
          function enviado() {
            alert('Informacion Enviada')
          }
</script>
<button type="button" name="button" id="boton" onclick="hizoClick();">Enviar</button>

</form>
</body>
</html>
    
asked by TOPOFGR 13.07.2018 в 23:46
source

1 answer

0

You had two problems. You were missing quotes when you opened the cols property of the textarea and you were missing the } to close the function hizoClick

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>
    Obligatorio
    </title>
    <link rel="stylesheet" href="./css/Estilo.css">
    <link rel="stylesheet" href="./css/EstilosChico.css"
            media="screen and (max-width: 600px)">
  </head>    
  <body>
<form action="no_existe.html" method="get" id="miformulario">    
<textarea rows="8" cols="80" id="comentarios" placeholder="Ingrese los comentarios" ></textarea>
<script>
          function hizoClick() {
            event.preventDefault();
            var text = document.getElementById("comentarios").value.toUpperCase();
            if (text.indexOf("EXCELENTE") != -1) {
              alert("El campo comentarios contiene Excelente");
            } else {
              document.getElementById("miformulario").submit();
              enviado();
            }
          }
</script>
<script>
          function enviado() {
            alert('Informacion Enviada')
          }
</script>
<button type="button" name="button" id="boton" onclick="hizoClick();">Enviar</button>

</form>
</body>
</html>
    
answered by 13.07.2018 в 23:52