skip to Main Content

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("");
            }
        })
    })
})

2

Answers


  1.     $(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();

    Login or Signup to reply.
  2. $(document).ready(function () {
        $('#message').submit(function (e) {
            e.preventDefault()
            $.ajax({
                url: 'processmsg.php',
                data: $(this).serialize(),
                method: 'POST',
                success: function (resp) {
                    $('#message')[0].reset();
                }
            });
        });
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search