Clear form

0

Well my question is that I must add to the javascripr for when I click on the submit in this case I will clear the text box that in my case is one, that is the textarea. Thanks in advance this is my code

 <textarea id="user_message_textarea"style="resize:none;height:100px;width:700px;" class="form-control" placeholder="Texto que voy a poner en el placeholder"></textarea>
                                                        <br>
                                                        <button id="user_message_button" type="button" class="button">Enviar</button>
                                                    </center>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                    <div id="snackbar_nuevo_servicio">Mensaje enviado. Gracias</div>
                        <script>
                            var showing_snackbar = false;
                            function user_message_success(){
                                var x = document.getElementById("snackbar_nuevo_servicio");
                                var b = document.getElementById("user_message_button");
                                x.className = "show_nuevo_servicio";
                                b.className = "btn btn-primary btn-md disabled";
                                showing_snackbar = true;
                                setTimeout(function(){ x.className = x.className.replace("show_nuevo_servicio", ""); showing_snackbar = false; b.className = "btn btn-primary btn-md";}, 3000);
                            }


                            $("#user_message_button").click(function(){
                            if(($("#user_message_textarea").val()).trim()  !== ""){
                            if(showing_snackbar == false){
                            $.post("user_message.php",
                            {
                            user_message:   $("#user_message_textarea").val()
                            },
                            function(data, status){
                            if(status == "success"){
                            user_message_success();
                                            }
                                        });
                                    }
                                }
                            });


                            </script>
    
asked by Speakers95 02.12.2018 в 09:12
source

2 answers

0

You should do a reset. That is:

document.getElementById("user_message_button").reset();

In case of not being in a form (because I do not see the label), you can "empty" if you want the textarea, that is:

$("#user_message_textarea").val('');
    
answered by 02.12.2018 в 11:14
0

A simple way to delete an input is:

$('.borrar').click(function(){
   $('#user_message_textarea').val('');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<textarea name="" id="user_message_textarea" cols="30" rows="10">Hola Mundo</textarea>
<button class="borrar">Borrar</button>
    
answered by 02.12.2018 в 23:51