Submitting HTML form in JQuery dialog
I am trying to convert an existing HTML form and make it appear in JQuery dialog. I am not sure how to change the code so the data is submitted after clicking the submit buton. My code is a follows:
Old form:
<form method="p开发者_开发知识库ost" name="callbackrequest" id="ccallbackrequest" action="action.php" onsubmit="return validateThis(this)">
<button type="submit" class="submit">Submit Request</button>
New form:
buttons: {
"Submit": function() {
if ( bValid ) {
HERE GOES THE CODE!
$( this ).dialog( "close" );
}
Then there is the new form:
<form class="center" method="post" name="callbackrequest" id="ccallbackrequest" action="??">
fields listed
no submit button
</form>
Any advice on how should I handle this?
Let's take it one step further...here's a dialog form submit with ajax!
<form id="modalform" style="display:none">
<input type="text" name="something">
<input type="text" name="somethingelse">
</form>
$("#modalform").dialog({ //Shows dialog
height: 250,
width: 450,
modal: true,
buttons: {
"Cancel": function() {
$( this ).dialog( "close" );
},
"Save": function() {
$.ajax({
url: "/url/to/submit", //
timeout: 30000,
type: "POST",
data: $('#modalform').serialize(),
dataType: 'json',
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("An error has occurred making the request: " + errorThrown)
},
success: function(data){
//Do stuff here on success such as modal info
$( this ).dialog( "close" );
}
}
});
Try $('#ccallbackrequest').submit();
. The submit method just submits whichever form is returned by the selector.
You just need to put in
$("#FORM_ID").submit()
精彩评论