How can I refresh a form made with ajax so that the inputs are clean?

1

I have a form made with ajax using Ajax.BeginForm this I have it in a modal, the problem that I have is that when I send the form I make the modal one close with jQuery but if I open the modal the values of the inputs that I had previously entered are still there ... I need to refresh the modality when sending the form so that the input of my form is cleaned.

How can I achieve this?

What he tried was that he places in onComplete a $("input").val(" ") but I do not know if there is some other better way to do it, as I mentioned at the beginning maybe refresh the modality when sending the form or clean the input from another way.

    
asked by vcasas 22.06.2018 в 16:42
source

2 answers

2

try this function after submit

    function limpiar()
    {
    settimeout('document.form.reset()',2000);//le dices al form que se resetee
    }

    onsubmit="return limpiar()"

//una solucion rapida enla etiqueta form
<form action="" onsubmit="this.submit(); this.reset(); return false;">

//otro metodo 

<script type="text/JavaScript">
    function reset() {
        document.formulario.campo.value = "";
        return true; 
    }
</script>


<form name='formulario' action='' method='post'onsubmit='return reset()'
>

    <input name="campo" type="text">
    
answered by 22.06.2018 / 17:06
source
1

Here is a very clear example of how you can perform the operation

<form id="formEjemplo">
     <input type="text" placeholder="Nombre...">
     <input type="text" placeholder="Edad...">
     <input type="text" placeholder="Email...">
     <select>
        <option value="0">Seleccionar...</option>
        <option value="0">Mexico</option>
        <option value="0">Estados Unidos</option>
     </select>
     <label>Sexo:</label>
     <input type="radio" name="sexo">M
     <input type="radio" name="sexo">F
     <button type="button" id="btnLimpiar">Limpiar</button>
</form>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
   $("#btnLimpiar").click(function(event) {
       $("#formEjemplo")[0].reset();
   });
</script>
    
answered by 22.06.2018 в 17:17