SharePoint Postback check using Javascript

I have to tick ‘All Day Event’ check box for SharePoint Calendar Event input form.
So add below code into new form


$(document).ready(function () {

var $checkBoxAllDayEvent = $("span[title='All Day Event']> input");
if( $checkBoxAllDayEvent.length > 0){

//instead setting the box checked, better to call the click event
if( !$checkBoxAllDayEvent.attr("checked") ){
$checkBoxAllDayEvent.click();
}
}
});

At the beginning it works fine but when I un-tick the check box again, it reload the form again and then the script loaded again so there is no way to un-tick the check box.
So I need to check whether this form is from postback or not but I can’t find any internal SharePoint javascript variable or function to check postback.

So the only way is check document.referrer and document.location.href.


$(document).ready(function () {
if( document.referrer != document.location.href )
{
var $checkBoxAllDayEvent = $("span[title='All Day Event']> input");
if( $checkBoxAllDayEvent.length > 0){

//instead setting the box checked, better to call the click event
if( !$checkBoxAllDayEvent.attr("checked") ){
$checkBoxAllDayEvent.click();
}
}
}
});

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: