It's as simple as calling the $.submit()
method on the form itself:
$("#formID").submit(); // jQuery
document.getElementById("formID").submit(); // Javascript
Or if you're using the name attribute only:
$("form[name='formName']").submit(); // jQuery
document.formName.submit(); // Javascript
If you're only interested in redirecting the page after you submit the data, you could do this from the callback of the $.post()
call:
$.post("process.php", { 'foo':$(".bar").val() }, function(result) {
window.location = "thanks.php";
});
Update:
The asker indicated in the comments below that no form actually exists. I would suggest creating one:
var myForm = $("<form>")
.attr({'method':'post','action':'process.php'})
.appendTo("<body>");
And then adding your data:
$("<input>")
.attr({'type':'hidden','name':'firstname'})
.val("Jonathan")
.appendTo(myForm);
And later, when you're ready, submit it:
$(myForm).submit();