Dynamically create a form to submit?

I am trying to create an HTML form action when the user clicks the submit button.

Thus, the user fills out the form, clicks the submit button, then the action is created, then it is actually submitted. The reason is that the form has a load on it, which will be passed to the script.

How do I do this with jQuery?

+6
jquery
source share
3 answers

Unconfirmed, but this should at least help you:

$('#myForm').submit(function (event) { var action = ''; // compute action here... $(this).attr('action', action); }); 
+11
source share

Use jQuery submit event:

 $(document).ready(function() { $('#yourFormId').submit(function() { $(this).attr('action', 'dynamicallyBuildAction'); return false; }); }); 
+3
source share

A simple Javascript solution will have a function:

 function changeAction() { this.action = 'the dynamic action'; return true; } 

In the form, you must set the onsubmit event:

 <form ... onsubmit="return changeAction();"> 

To do the same with jQuery, follow these steps:

 $(function(){ $('IdOfTheForm').submit(function(){ this.action = 'the dynamic action'; return true; }); }); 
0
source share

All Articles