.I have this code1:
<form method="GET" action="picture.php">
.usually the value of i1 will be sent if i use this code2:
<input type="submit">
.Is there a way to trigger the "submit" function by using a jquery instead of code2? help pls!
-
Please, add the tags "jquery" and "javascript" next time. Thanks.Yasir Arsanukayev– Yasir Arsanukayev2011年03月02日 15:47:52 +00:00Commented Mar 2, 2011 at 15:47
-
Alright.. i'm sorry for that.zerey– zerey2011年03月02日 15:57:34 +00:00Commented Mar 2, 2011 at 15:57
-
Please include the full HTML of the form you are using.McHerbie– McHerbie2011年03月02日 19:31:13 +00:00Commented Mar 2, 2011 at 19:31
3 Answers 3
<form method="GET" action="picture.php" id="picture-form">
... followed by the following call in javascript, wherever it might be required ...
$('form#picture-form').submit();
Note that an ID has been added to the form for an accurate jQuery reference. just doing $('form').submit(); could be very evil.
Fully fledged example follows.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<form method="GET" action="picture.php" id="picture-form">
<a href="javascript:void(0);" onclick="$('form#picture-form').submit();">Submit me!</a>
</form>
3 Comments
take a look at this link : http://api.jquery.com/submit/ - Bind an event handler to the "submit" JavaScript event, or trigger that event on an element.
Comments
There's even no need for jQuery, you can do it in vanilla JavaScript:
<form method="GET" action="picture.php" id="picture-form">
<a href="#" onclick="document.getElementById("picture-form").submit()>Click me!</a>
...
</form>