Home > Back-end >  how to clear text boxes after a work have been done?
how to clear text boxes after a work have been done?

Time:01-03

i wrote a code that will add records to data base then return the message to a specific div now I need to know how to clear text boxes after I get the result to the div?

$(document).ready(function() {
    $('#message').submit(function(e) {
        e.preventDefault()
        
        $.ajax({
            url: 'processmsg.php',
            data: $(this).serialize(),
            method: 'POST',
            success: function(resp) {
                $('#error_msg').html(resp);
            }
        })
    })
})
$(document).ready(function() {
    $('#message').submit(function(e) {
        e.preventDefault()
        
        $.ajax({
            url: 'processmsg.php',
            data: $(this).serialize(),
            method: 'POST',
            success: function(resp) {
                $('#error_msg').html(resp);
                $('#FullName').html("");
                $('#Email').html("");
                $('#PhoneNumber').html("");
                $('#Message').html("");
            }
        })
    })
})

CodePudding user response:

    $(document).ready(function() {
    $('#message').submit(function(e) {
        e.preventDefault()
        

        $.ajax({
            url: 'processmsg.php',
            data: $(this).serialize(),
            method: 'POST',
            success: function(resp) {
                $('#error_msg').html(resp);

                let frm = document.getElementsById('#message')[0];
                frm.reset();  // Reset all form data
                    
            }
        })

    })
})

if it's a regular html form then from.reset();

CodePudding user response:

$(document).ready(function () {
    $('#message').submit(function (e) {
        e.preventDefault()
        $.ajax({
            url: 'processmsg.php',
            data: $(this).serialize(),
            method: 'POST',
            success: function (resp) {
                $('#message')[0].reset();
            }
        });
    });
});
  • Related