how to avoid page reload in $(document).ready(function()

%3CLINGO-SUB%20id%3D%22lingo-sub-2624576%22%20slang%3D%22en-US%22%3Ehow%20to%20avoid%20page%20reload%20in%20%24(document).ready(function()%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2624576%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Team%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAfter%20dropdown%20changevent%20completion%20page%20gets%20reloaded%20everytime.%20I%20want%20to%20stop%20after%20function%20execution.%20Kindly%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSCRIPT%20type%3D%22%26quot%3Btext%2Fjavascript%26quot%3B%22%3E%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3B%24(%20document%20).ready(function()%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3B%7B%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3Balert(%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3B%2339%3Bpage%20load...%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3B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%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3B%7B%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3Balert(%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3B%2339%3Bchange%20event%20function%20called...%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3B%2339%3B)%3B%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3B%7D%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bamp%3Bgt%3B%3C%2FSCRIPT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2624576%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Esharepoint%20javascript%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2625164%22%20slang%3D%22en-US%22%3ERe%3A%20how%20to%20avoid%20page%20reload%20in%20%24(document).ready(function()%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2625164%22%20slang%3D%22en-US%22%3EYour%20code%20should%20not%20reload%20the%20page%2C%20Do%20you%20get%20the%20%22page%20load...%22%20message%20twice%3F%3CBR%20%2F%3E%3CBR%20%2F%3EWhich%20browser%20are%20you%20using%3F%3CBR%20%2F%3E%3CBR%20%2F%3EpreventDefault()%20might%20help%2C%20change%20%24('select%5Bid%5E%3D%22ctl00_ctl04_ctl00_ddlCrossWebLookupColumn%22%5D').change%20to%3CBR%20%2F%3E%3CBR%20%2F%3E%24('select%5Bid%5E%3D%22ctl00_ctl04_ctl00_ddlCrossWebLookupColumn%22%5D').change(function(e)%3CBR%20%2F%3E%7B%3CBR%20%2F%3Ealert('dropdown%20change%20event%20called')%3B%3CBR%20%2F%3EfunctionTest()%3B%3CBR%20%2F%3Ee.preventDefault()%3B%3CBR%20%2F%3E%7D)%3B%3CBR%20%2F%3E%3CBR%20%2F%3EDoes%20the%20page%20reload%20with%20e.preventDefault()%3F%3C%2FLINGO-BODY%3E
New Contributor

Hi Team,

 

After dropdown changevent completion page gets reloaded everytime. I want to stop after function execution. Kindly help.

 

<script type="text/javascript">

$( document ).ready(function()
{
alert('page load...');
$('select[id^="ctl00_ctl04_ctl00_ddlCrossWebLookupColumn"]').change(function()
{
alert('dropdown change event called');
functionTest();
});

 

});

function functionTest()
{
alert('change event function called...');
}

</script>

1 Reply
Your code should not reload the page, Do you get the "page load..." message twice?

Which browser are you using?

preventDefault() might help, change $('select[id^="ctl00_ctl04_ctl00_ddlCrossWebLookupColumn"]').change to

$('select[id^="ctl00_ctl04_ctl00_ddlCrossWebLookupColumn"]').change(function(e)
{
alert('dropdown change event called');
functionTest();
e.preventDefault();
});

Does the page reload with e.preventDefault()?