Submit form with jquery plug
I am trying to submit the form with jquery. I am using bootstrap modal window. Here is a js fiddle. Am i missing something? thanks alot
Update: I am trying to submit the form using ajax. I also tried but not luck.
$('#comment_form').on('submit', function(){
$.post("/yourReceivingPage", $(this).serialize(), function(){
// Hide the modal
$("#my-modal").modal('hide');
});
// Stop the normal form submission
return false;
});
You refer to the wrong element, I have a working example for you, please check and let me know if it works for you:
$(document).ready(function() {
$('#comment-form-submit').click(function() {
$('#comment_form').submit();
alert('Handler for .submit() called.');
return false;
});
});
jsFiddle Working Demo
And for AJAX solution you need to refer to familiar and already discussed issue:
jquery serialize and $.post
Edited: Referring to your question about how to extract the ID of the clickable link, this code will do it for you:
$(document).ready(function() {
$(".comments.no").mouseover(function() {
myDivsId = this.id; // as you mouse over on the link it will be stored in Global Var and then transferred anywhere you wish.
});
$('#comment-form-submit').click(function() {
$('#comment_form').submit();
alert('Handler for .submit() called + div's ID = ' + myDivsId);
return false;
});
});
jsFiddle live demo
您需要为评论表单提交按钮添加点击事件。
$(document).on('click','#comment-form-submit', function() {
$('#comment_form').submit(function() {
alert('Handler for .submit() called.');
return false;
});
});
You are looking for just submit(). What you are doing in your example is creating a function that will be run when the form is submitted. Also you are not setting up the handler for the clicking to submit the form.
// This creates submit handler for the form
$('#comment_form').submit(function() {
alert('Handler for .submit() called.');
return false;
});
// This creates the on click handler for the submit button
$('#comment-form-submit').on('click', function() {
// This actually submits the form
$('#comment_form').submit();
});
链接地址: http://www.djcxy.com/p/45958.html
下一篇: 用jquery插件提交表单