send alert for if in javascript

3

I am creating a form, and I have a situation of a field that has to be filled depending on the multiplication of some if it is bigger than it has to fill the field if it is smaller that you do not have to fill it.

I am doing this with javascript but I am new and I do not know if the code is correct because IF

this is my code: javascript

Javascript Code:

        <script>
            function continuar(){
                var Num = document.getElementById("multiprica").value;
                var Acc = document.getElementById("Plan_Accion").value;
               if(Num > 4){ 
                if (Acc.length==""){
                    var errorNombre=document.createElement('p');
                    errorNombre.innerHTML= 'No escribiste tu nombre';                   
                    document.getElementById("Comentarios").appendChild(errorNombre);
                    return false;
                }
            }
            }
         </script> 

This is my field that needs to be filled

HTML Code:

<div class="col-xs-17">
                            <label for="sel1">Plan de Acción: es un plan que prioriza las iniciativas más importantes para cumplir con ciertos objetivos y metas</label>
                            <input hidden="¿QUE?" name="ID_QUE" value="1">  
                            <textarea class="form-control" rows="3" name="Plan_Accion" value="Plan_Accion"></textarea>
                        </div>

this is the button that calls the javascript function HTML code:

<div class="btn-group btn-group-lg">
                              <button type="submit" class="btn btn-primary" onclick="return continuar();">Continuar</button> </div>
    
asked by antonio sanchez 30.08.2018 в 19:05
source

1 answer

5

Your code works with some changes. First, you may have an error in the id of the variable Num . I changed the id to multiplica . Then you want to access the element with id Plan_Accion that does not exist in your code. I changed the property name by id of your text area and it worked.

<script>
            function continuar(){
                var Num = document.getElementById("multiplica").innerHTML;
                var Acc = document.getElementById("Plan_Accion").value;
               if(Num > 4){ 
                if (Acc.length==""){
                    var errorNombre=document.createElement('p');
                    errorNombre.innerHTML= 'No escribiste tu nombre';                   
                    document.getElementById("Comentarios").appendChild(errorNombre);
                    return false;
                }
            }
            }
         </script> 
 
<div class="col-xs-17">
    <label for="sel1">Plan de Acción: es un plan que prioriza las iniciativas más importantes para cumplir con ciertos objetivos y metas</label>
                            <input hidden="¿QUE?" name="ID_QUE" value="1">  
                            <label id="multiplica">5</label>
                            <textarea class="form-control" rows="3" id="Plan_Accion" value="Plan_Accion"></textarea>
                        </div>


<div class="btn-group btn-group-lg">
                              <button type="submit" class="btn btn-primary" onclick="return continuar();">Continuar</button> </div>
<div id="Comentarios"></div>
    
answered by 30.08.2018 / 19:15
source