Get submitted form action

I have the following code that runs every time a user submits a form on my site.

I want to change it a bit so that it checks the performance of the view and is based on the presence of a specific keyword, runs some code.

My code is as follows:

$("form").submit(function() { //do some generic stuff var formAction = ""; //get the action of the submitted form if (formAction.indexOf('keyword') !== -1) { //do some specific stuff for these forms } }); 

How do I get the action from the form that caused this call?

+7
source share
3 answers
 $("form").submit(function() { //some stuff... //get form action: var formAction = $(this).attr("action"); //some other stuff... }); 
+12
source

if you need javascript without jQuery:

 var action=document.getElementById('formId').action 

with jQuery:

 var action=$('#formId').attr('action'); 
+8
source

You can get the attr action this way -

 var formAction = $(this).attr("action"); 
+3
source

All Articles