Reputation: 5
Can anyone please tell me how to insert data into database without page refresh and without using any button. Facebook wall posts area is an example. User writes whatever he wants in input field and he has to press ENTER to submit the data into database instead of using a submit button.
Upvotes: 0
Views: 73
Reputation: 2322
If you're using jquery, you can do something along the lines of:
$(document).keydown(function(e) {
if(e.which == 13) {
your submit code
}
}
Upvotes: 1
Reputation:
Browsers automatically submit a form if you hit enter within a <input type="text">
element.
Try
<form action="" onsubmit="alert(document.getElementById('t').value); return false;">
<input type="text" id="t">
</form>
Upvotes: 0