In my user.php page I've a button called PARTICIPATE. After click on this button it's showing a POPUP box with a Register Form using Jquery Reveal Plugin (for popup). Now I validate this form with Jquery Plugin. After validation is complete I'm sending the request to Php suing Jquery/Ajax method. After successfully register I get the response and showing the success message on this POPUP BOX by hiding the html form. After few second the POPUP box will disappear.
Everything is ok now but the POPUP BOX with success message is now showing exactly to the top of the window. I want to show it at the middle or little bit lower. Can you please tell me How can I do this ?
My code is following : (This is the function which animate the popup box to top)
<script>
function scrollToElement(selector, callback){
var animation = {scrollTop: $(selector).offset().top};
$('html,body').animate(animation, 'slow', 'swing', function() {
if (typeof callback == 'function') {
callback();
}
callback = null;
});
}
</script>
This is the code which validate the form and I'm calling the scrollToElement
method :
<script>
$(document).ready(function() {
// validate signup form on keyup and submit
$("#campaign").validate({
submitHandler: function(form) {
$.ajax({
url: form.action,
type: form.method,
//async: false,
data: $(form).serialize(),
beforeSend : function (){
$('input[type=submit]').attr('disabled', true);
},
success: function(response) {
$('#formError').html(response);
$(form).hide();
//return false;
scrollToElement('#myModal2');
setTimeout(function() {
$('input[type=submit]').attr('disabled', false);
location.reload();
}, 5000 );
}
});
},
rules: {
phone: "required",
postal: "required",
suburb: "required",
state: "required",
pcode: "required",
terms : "required",
terms1 : "required",
purpose: {
required: true,
maxlength: 150
},
workforce: {
required: true,
maxlength : 150
},
plan_implement : {
required: true,
maxlength : 150
},
},
messages: {
terms : "Required",
terms1 : "Required",
phone : "Required",
postal: "Required",
suburb: "Required",
state: "Required",
pcode: "Required",
purpose: {
required: "Required",
maxlength: "Only 150 characters allowed"
},
workforce : {
required: "Required",
maxlength: "Only 150 characters allowed"
},
plan_implement : {
required: "Required",
maxlength: "Only 150 characters allowed"
},
}
});
});
</script>
Html form
<div id="myModal2" class="reveal-modal3">
//my html form....
</div>