___ ___ erkimt Javascript function Onclick In conflict with the form? ______ qstntxt ___

I have a form that sends data to another page, I would like to reset some inputs after submitting the form, so I tried this:

%pre%

But I did not succeed, I tried to reset the input several ways, putting in a function js (which would be right in the case), tried jquery among others but I did not succeed, so I believe there may be some conflict within my form that might be causing this function problem not to generate the expected result (which in case is reset the text area description).

    
______ azszpr316756 ___

%code% is in the wrong place. You should put it in the %code% tag. Another problem is that %code% is only applicable to the %code% object, not to an individual form element.

As you can not clear the field in the submit (otherwise it will be sent empty), call a function after a small delay using %code% on %code% :

%pre%

And put the %code% function in JavaScript by clearing the field with %code% :

%pre%

Or you could also do everything in %code% without calling function:

%pre%     
___

1

I have a form that sends data to another page, I would like to reset some inputs after submitting the form, so I tried this:

<form name='protocolo' id='protocolo' class='excluirclienteform' action='makeprotocolo.php'  target="_blank" method="POST" enctype="multipart/form-data">
                    <br>
                    <label>Selecione uma empresa</label><br>
                    <select name='id' class="selects2"  required>
                        <option value="">selecione a empresa</option>
                            <?php
                            $buscarid=$pdo->prepare("SELECT ID,nome FROM usuario WHERE permissao = 1 ORDER BY ID ASC");
                            $buscarid->execute();
                            while($linha=$buscarid->fetch(PDO::FETCH_ASSOC)){
                                echo "<option  value=".$linha["ID"].">".$linha["ID"]." ".$linha["nome"]."</option>";
                            }
                            ?>
                        </option>
                    </select>
                    <br>
                    <label>Selecione um item</label>
                    <br>
                    <select name='item' class="selects2"  required>
                        <option value="">selecione a empresa</option>
                            <?php
                            $buscarid=$pdo->prepare("SELECT id,nome FROM protocolo_item order by nome asc");
                            $buscarid->execute();
                            while($linha=$buscarid->fetch(PDO::FETCH_ASSOC)){
                                echo "<option  value=".$linha["id"].">".$linha["id"]." ".$linha["nome"]."</option>";
                            }
                            ?>
                        </option>
                    </select>
                    <br>
                    <label>Quantidade</label>
                    <br>
                    <input type='number' step="1" name='quantidade' id='quantidade' size='20' maxlength="10">
                    <br>
                    <label>Descrição</label>
                    <br>
                    <textarea rows="4" cols="50" name="descricao" id='descricao' maxlength="500"></textarea>
                    <br><br>
                    <button type='submit' id='inseriritem' name='enviar' onsubmit="document.getElementById('#descricao').reset();">Inserir</button>
                    <br><br>
                </form>

But I did not succeed, I tried to reset the input several ways, putting in a function js (which would be right in the case), tried jquery among others but I did not succeed, so I believe there may be some conflict within my form that might be causing this function problem not to generate the expected result (which in case is reset the text area description).

    
asked by anonymous 21.07.2018 / 01:25

1 answer

1

onsubmit is in the wrong place. You should put it in the <form> tag. Another problem is that reset() is only applicable to the <form> object, not to an individual form element.

As you can not clear the field in the submit (otherwise it will be sent empty), call a function after a small delay using setTimeout on onsubmit :

<form onsubmit="setTimeout(limpa, 100)"...
                  ^^^^^^^

And put the limpa() function in JavaScript by clearing the field with value = '' :

<script>
function limpa(){
   document.getElementById('descricao').value = '';
}
</script>  

Or you could also do everything in onsubmit without calling function:

<form onsubmit="setTimeout(function(){ document.getElementById('descricao').value = '' }, 100)"...
    
21.07.2018 / 01:51