Jquery Ajax clear form after submit

How to clear your form after submission using Jquery

The easiest way is using

$('#formId').trigger("reset")

Example

$(document).ready(function(e) {
    $("#btntambah").click(function(){
        var nama = $("#txtnama").val(); // cara jquery mangambil value dari object html dengan id txtnamaprd
        var kota = $("#txtkota").val();
        var detail = $("#txtdetail").val();
       

    $.ajax({ // ajax jqeury untuk mengirim value dengan methode post
            type: "POST",
            url: urlService+'proses.php?mode=add', // proses.php berisi php dengan script sql insert
            data:"txtnama="+nama+'&txtkota='+kota+'&txtdetail='+detail,
            success: function(data){
                $("#result").html(data); // callback respon ajax apabila proses.php berhasil, hasil dikembalikan ke halaman html di tag dengan id #result
            }
    });
   
$('#frmnasabah').trigger("reset") // form field di reset
   

    })
});

Hery Purnama – 081.223344.506 – inhousetrainer@yahoo.com.
Freelance IT Trainer, Trainer Excel VBA Macro, Trainer Sencha ExtJS, Trainer Google Map API, Trainer SPSS, Trainer MS Project, Trainer Primavera, Trainer Google Sktechup 3D, Trainer Android Phonegap, Trainer Oracle, Trainer SQL Server, Trainer MySQL, Trainer PHP Jquery Mobile , Trainer Java, Trainer HTML5 Javascript, Trainer SEO Internet Marketing, Trainer Project Management, Trainer SMS Gateway, Trainer CMS WordPress, ITIL, COBIT

Author: Inhouse Trainer freelance

Hery Purnama 081.223344.506 - Freelance Trainer , Excel VBA Macro, Android, Phonegap, ITIL, COBIT, Google Map API, Sketchup3D , MS Project, Sencha ExtJS, Oracle , MySQL DBA, MS. Access VBA, Primavera P6, MS Project ,Jquery, Yii, CodeIgniter. laravel, CATIA 3D, Unity 5 , PMBOK, PMO, TOGAF, PRINCE2 - Call : 081.223344.506 | PinBB : 7DC633AA| Email / YM : inhousetrainer@yahoo.com | FB : inhousetrainer | TW : inhousetrainer

Leave a Reply

Your email address will not be published. Required fields are marked *