Clear only the field I want

1

I have this script:

$(".btn_contact").click(function () {

    $.ajax({
        type: "POST",
        url: "./Inserir16",
        data: $("#feedback_form16").serialize(), // serializes the form's elements.
        dataType: "json",
        success: function (data)
        {
            $(".success_messages").removeClass('hide'); // success message
        }, 
        error: function(data){
            $(".error_message").removeClass('hide'); // error message
        },
        complete: function()
        { 
            $("#feedback_form16").find('input').val(''); //clear text
        }           
    });

});

This eliminates all input fields, but I only want to delete a specific field of the form, which has the name and id of Qty. Can anyone help?

    
asked by anonymous 11.07.2018 / 13:13

3 answers

1

Your HTML probably has id s duplicates and using #Qtd is not finding the correct element. An HTML page can not have the same id in more than one element.

Place in the% w / o of% you want to clear a input attribute, for example:

<input data-qtd="Qtd"...>

And in% Ajax% wont put:

$("input[data-qtd='Qtd']").val('')
    
12.07.2018 / 01:25
2

It's very simple, if you're using jQuery, just use this code:

$("input[name='nome-do-input']").val('');

Or, if there are inputs with the name that you want elsewhere than the form you want to clean, you can follow the reasoning line of your current code like this:

$("#feedback_form16").find('input[name="nome-do-input"]').val(''); //clear text
    
11.07.2018 / 13:21
2

Hello,

Currently you clear all form fields in the complete function () with this code:

$("#feedback_form16").find('input').val(''); //clear text

So you need to clean only the input quantity, right? Add an id to the desired input, like this:

<input type="text" name="quantidade" id="quantidade" />

And in the complete function () reference it this way:

$("#quantidade").val(''); //clear text
    
11.07.2018 / 13:21