How To Run Function From External File As Action For Form?
Description: At present I have html file with a form like the following: I have javascript fu
Solution 1:
Change your HTML to:
<form id="my_form" action="" onSubmit="OnAction()" method='post'></form>
You just need to do this:
function OnAction() {
// OnAction here
};
Or better way is to put your event with Jquery:
HTML:
<form id="my_form" action="" method='post'></form>
JS:
$("#my_form").on("submit", function() {
/* OnAction here*/
});
Solution 2:
$('#my_form').on('action', function() {
The event that fires when a a form is submitted is submit
not action
. Use that (with a real URL in the action with a server side fallback in case the JS fails; don't forget to preventDefault()
).
Solution 3:
Add reference of your external file to your HTML file.
Solution 4:
In your HTML:
...
<formmethod="post"id="myform"><inputtype="submit"/></form><scriptsrc="abc.js"type="text/javascript"></script></body>
In your js. file:
var elem = document.getElementById("myform");
elem.addEventListener("submit", function() {
//
},false);
Post a Comment for "How To Run Function From External File As Action For Form?"