3

I just wanted to know how I can run a function on a specific form name? instead of just any form.. my code is below you don't really need to know anything else, its for an ajax call.

$('form').on('submit', function (e) {
e.preventDefault();

          $.ajax({
            type: 'post',
            url: '<?php echo $config['website']['url']; ?>/assets/hk/ajax/muteorban.php',
            data: $('form').serialize(),
            success: function (data) {
              var div = document.getElementById('contentArea_muteorban');
          div.innerHTML = div.innerHTML + data;
            }
          });

        });

      });
KAD
  • 10,972
  • 4
  • 31
  • 73
Josh Hallow
  • 359
  • 3
  • 15

1 Answers1

4

You can use name selector $('form[name="myFormName"]') as follows :

$('form[name="myFormName"]').on('submit', function (e) {
e.preventDefault();

          $.ajax({
            type: 'post',
            url: '<?php echo $config['website']['url']; ?>/assets/hk/ajax/muteorban.php',
            data: $(this).serialize(), ///////// <<<<<<<<<<<<< you can use $(this) here
            success: function (data) {
              var div = document.getElementById('contentArea_muteorban');
          div.innerHTML = div.innerHTML + data;
            }
          });

        });

      });
KAD
  • 10,972
  • 4
  • 31
  • 73