Remove requirement for a click event from existing javascript - javascript

I have a modal popup that used to have a submit button.
As the content of the form is now pre filled, I want to remove the submit and have the form auto submitted.
The section of javascript that deals with this is below
afterShow: function () {
$(document).on('submit', '#back-in-stock-popup-wrapper form[name="back_in_stock"]', function () {
$.post('ajax/back_in_stock_subscribe_pop_up.php', $('#back-in-stock-popup-wrapper form[name="back_in_stock"]').serialize(), function (data) {
$('#contact_messages').html(data);
if ($('.messageStackSuccess').length) {
$('.back-in-stock-popup-wrapper-button-row').hide();
$('.back-in-stock-popup-content-wrapper').hide();
}
});
return false;
});
}
Instead of it waiting for a submit event, I want it to follow the code.
I'm hopeless with javascript and I thought I could just change it to
$(document)('#back-in-stock-popup-wrapper form[name="back_in_stock"]', function () {
but that didn't work.
How do I tell javascript to just proceed without waiting for the submit from the button click?

Just remove the outer call like so:
afterShow: function () {
$.post('ajax/back_in_stock_subscribe_pop_up.php', $('#back-in-stock-popup-wrapper form[name="back_in_stock"]').serialize(), function (data) {
$('#contact_messages').html(data);
if ($('.messageStackSuccess').length) {
$('.back-in-stock-popup-wrapper-button-row').hide();
$('.back-in-stock-popup-content-wrapper').hide();
}
});
return false;
}

Related

jquery if clicked multiple times

This is just a small piece of code of my function. The function is by default false, when you click on the #my-button the function will be true and run.
But now I want that when you click on the same button again, the function will be false again and should stop working.
And that should he be doing every time you click the button (it would be great if this is also possible with classes instead of the id)
$('#my-button').toggle(function () {
sliderPaused = true;
}, function () {
sliderPaused = false;
});
I use a toggle function, only this does not work for me. Is there something wrong at my code?
$('#my-button').click(function () {
if (sliderPaused) sliderPaused = false;
else sliderPaused = true;
});

how to unbind onbeforeunload event on javascript function call and page refresh

Please help me how to unbind onbeforeunload event on javascript function call .
Also I want to unbind onbeforeunload on page refresh.
Actually I want to give pop up alert on page exit .For this I have successfully unbinded onbeforeunload from form submit button and anchor tags. Kindly help me. The code I have used is
var jQuery = jQuery.noConflict();
jQuery(document).ready(function() {
jQuery(window).bind("onbeforeunload", function() {
return confirm("Do you really want to close?")
}
);
jQuery('a').on('click', function() {
jQuery(window).unbind('onbeforeunload')
});
jQuery("form").submit(function() {
jQuery(window).unbind('onbeforeunload')
});
});
Thanks
Do some minor change in your code, it will be work
jQuery(document).ready(function () {
window.onbeforeunload = function () {
return confirm("Do you really want to close?")
};
jQuery('a').on('click', function () {
jQuery(window).unbind('onbeforeunload')
});
jQuery("form").submit(function () {
jQuery(window).unbind('onbeforeunload')
});
});
Check this on jqfiddler, Message pop-up showing on refresh click here

how to undo the action DayPilot.Scheduler on event Resized without reloading the page?

How to undo the action DayPilot.Scheduler on event Resized on the last event i saved without reloading the page?
Here is my code:
dp.onEventResized = function (args) {
if (confirm('Are you sure you want to edit this?')) {
--do some code --
}
else
{
window.location.reload();
//undo the last event..
}
};
You should use onEventResize to display the confirmation dialog. This event is called before the default action (while onEventResized is called after it). You can cancel the default action using args.preventDefault():
dp.onEventResize = function (args) {
if (!confirm('Are you sure you want to edit this?')) {
{
args.preventDefault();
}
};
Keep the original action in the onEventResized handler:
dp.onEventResized = function (args) {
// submit changes
};

load exteral form into html div and try to on submit with validation but its not working

onclick =id(myModalssid) used to call the html(external_form_fields.html .formval) file in particular into div(.modal-body-id). that div contain form, i need validation of the form in on submit.
<script>
$('#myModalssid').click(function ()
{
$('.modal-body-id').load('external_form_fields.html .from_val');
alert('Message');
});
</script>
create function in jQuery for validation,
And call that function in your click event...
Just like:--
<script>
$('#myModalssid').click(function () {
$('.modal-body-id').load('external_form_fields.html .from_val');
alert('dgfdfgs');
formValidation();
});
function formValidation()
{
//Your validation Process...
}
</script>
You need to initialize the validation script when the form is loaded:
$('#myModalssid').click(function ()
{
$('.modal-body-id').load('external_form_fields.html .from_val', function() {
$('.form').on('submit', function() {
//your validation script
});
});
});

form keeps getting submit event without pressing submit button

I am trying to make a form so when user click button then it will submit but the problem is that it is keep getting on function even if I am not pressing submit button. here is my code
$(function () {
var url, container, form,
View = {
init: function () {
container = $('.container');
form = $('.search#form');
console.log(form);
View.loadViews();
$(document).on('submit', '#form', View.findView());
},
findView: function () {
console.log('helllo');
return false;
},
loadViews: function (view) {
$(container).load('search.html');
}
};
View.init();
});
In code above the line $(document).on('submit', '#form', View.findView()); keeps calling findView() method whereas I want to call it when user click submit button. How can I fix this?
When you bind it using $(document).on('submit', '#form', View.findView());, you are essentially calling the function and trying to bind the submit event to what the function returns, which is incorrect. Since findView() is returning false, this is equivalent of saying $(document).on('submit', '#form', false);
You need to bind View.findView() like below:
$(document).on('submit', '#form', View.findView); // note, no () at the end
you should pass reference of function not function returned value.
$(document).on('submit', '#form', View.findView);

Categories

Resources