How can I make an <a href="http://test/com/tag/test">Test</a>
act like a form button? And by acting like a form button I mean that when clicking the link to do a method="get"
or post in order to be able to capture it by get or post.
Not necessary has to be a link, I can adapt in order to make it work like that!
Assuming you have any element inside your form with an ID, you use jQuery to select that ID and attach a
click
event on it. On this particular case it will also use aget
to request data from/whatever.php
and you should fine tune it to use bothget/post
and serialize the forms data or not according to your needs.And without jQuery
If you want to submit a form using a link:
HTML --
JS --
Docs for
trigger()
: http://api.jquery.com/triggerIf you want to submit the form without leaving the page, you can use an AJAX call:
Docs for
$.ajax()
: http://api.jquery.com/jquery.ajaxNote that
.on()
is new in jQuery 1.7 and in this case is the same as using.bind()
.