Clean / Reset several forms

2

In my code I have 2 forms that once sent, I would like the previous data to be cleaned in each one of them. Currently only "clean" the search data of the "faith" form

<div id="actualiza">
<form name="fe" action="" method="post">
    <table border="2">
        <tbody><tr><td>Nombre de Usuario</td>
        <td><input name="txtbus" type="text"></td>
        <td><input name="btn1" value="Buscar" type="submit" onsubmit="this.reset()"></td></tr>
</form>     
</tbody></table>

<form name='contacto' method="POST" action="">
         <div><etiqueta>Nombre de Usuario:</etiqueta><input type='text' id="usuario" name="usuario" value='<?php echo $row['nombre_usuario']?>'></div>
        <div><etiqueta>Empleado:</etiqueta><input type='text' id="nombre" name="nombre" value='<?php echo $row['nombre']?>'></div>
<input name="btn2" value="Aceptar" type="submit" onsubmit="this.reset()">
    
asked by HGarcia 02.11.2017 в 16:19
source

2 answers

1

The first thing I notice about the sample code you are asking us is a couple of markup errors: The div updates does not close, the second form does not have a closing tag either, you close the table after form ...

Leaving these issues aside (which may confuse the browser that interprets that HTML ) the event onsubmit should go in form and not in input[type='submit'] .

For example, this way:

<div id="actualiza">
<form name="fe" action="" method="post" onsubmit="this.reset()">
    <table border="2">
        <tbody><tr><td>Nombre de Usuario</td>
        <td><input name="txtbus" type="text"></td>
        <td><input name="btn1" value="Buscar" type="submit" ></td></tr>
</tbody></table>
</form>     

<form name='contacto' method="POST" action="" onsubmit="this.reset()">
         <div><etiqueta>Nombre de Usuario:</etiqueta><input type='text' id="usuario" name="usuario" value='<?php echo $row['nombre_usuario']?>'></div>
        <div><etiqueta>Empleado:</etiqueta><input type='text' id="nombre" name="nombre" value='<?php echo $row['nombre']?>'></div>
<input name="btn2" value="Aceptar" type="submit">
</form>
</div>
    
answered by 02.11.2017 в 16:29
0

I think the problem is that you are doing a " <?php echo $row['nombre_usuario']?> " in the value of the input therefore it will never "reset"

Each time a form performs a submit, the values are restarted.

    
answered by 02.11.2017 в 18:20