Reputation: 8701
I am using jquery to call an action when a form is submitted. I am also using return false; to prevent the page from being refreshed. However, when I try to resubmit the form - it doesn't work, but I need it to (e.g. new data entered in the field).
Currently, I am using this structured:
<form action="" method="POST" id="myform">
<input type="text" name="test" value="test">
</form>
$(document).ready(function(){
$('#myform').submit(function(){
// Some action here
return false;
});
});
EDIT: I am not looking to submit the form. I just want it to fire a jQuery function every time the submit button is pressed. With the current example the action only works once (the first time the submit button is pressed). It seems like the preventing stops the functionality of the submit button completely.
EDIT2: Okay, let me clarify. I don't have a submit button. I only have a text input and whenever someone fills it and presses the Enter key (e.g. the form's submit is fired) I want to get this input value via jQuery and do something. The issue is that now I can only do this once (pressing enter the second time with new value in the text input does nothing). I am guessing the return false is causing this.
Upvotes: 2
Views: 1435
Reputation: 3290
Remove return false then it works. You are preventing to submit the form.
$(document).ready(function() {
$("myButton").click(function() {
$('#myform').submit(function() {
// Some action here
//return false;
});
});
});
Upvotes: 3