Reputation: 55
I have the following code, i want to enter submit function how do it?thank you
<script type="text/javascript"src="jquery.js"></script>
<form id="submit">
<textarea ID="UPDATE"></textarea>
<input type="submit" id="saveResult" value="Save All Data" />
</form>
<div id="displayResult"></div>
<script>
$("#saveResult").click(function(){
var firstname = $("#update").val();
lastname = $("#lname").val() ;
$.post("tes.asp",{update2:firstname,LName2:lastname} , function(data) {
$("#displayResult").html(data);
});
$('#update').val('');$('#lname').val('');
});</script>
Upvotes: 1
Views: 122
Reputation: 782285
Use:
$("#submit").submit(function() { ... });
The submit
event is triggered when the form is submitted either by clicking on a button or when pressing Enter in the last field.
Upvotes: 1
Reputation: 1309
I hope I have understood the question correctly.
So if you want to enable form submit when users hit enter on their keyboard,
//caching the target form element
var targetForm = $('#someformID');
targetForm .find('input').keypress(function(e) {
if(e.which == 13) {
targetForm.focus().submit();
}
}
Upvotes: 0