I have a form like this :
<form id="myform" action="something.php" method="post">
<input type="text" name="first_name" /><br />
<input type="button" id="submit" value="Send" />
</form>
I want to submit this form after getting successful message from some processes in JavaScript and jQuery. So I did it like this :
$(document).ready(function(e) {
$('#submit').click(function(event){
event.preventDefault();
$.post('process/process.php',
{
// I passed data here
},
function(data) {
if (data.result == '1') {
$('#myform').submit();
} else {
alert('Error #'+data.result+' occurred!');
}
},
'json'
);
});
});
But even after getting data.result == '1', the submitting form does not work. What's the problem here ?
Edit:
I've changed jQuery to :
$(document).ready(function(e) {
$('#submit').click(function(event){
$('#myform').submit();
)};
)};
So there is no condition now, but form did not submit.