submit values using jquery
.I have this code1:
<form method="GET" action="picture.php">
.usually the value o开发者_Go百科f 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!
<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>
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.
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>
精彩评论