You have to copy the function from project page to js file and link it both in your project page and enquiry.php. If you cannot change project page then you have to make a copy that will be available elsewhere.
In this case you should also refactor so that your click doesn't call anonimous function, set the code within to separate
function callEnquiry() {
$.colorbox.close();
console.log("setting location");
window.location.href="enquiry.php";
console.log("waiting for h2");
setTimeout(function(){$( "#h2" ).attr( "checked", "true" );
console.log("h2 set to checked");}, 500);
console.log("done");
}
and on click just call callEnquiry
$('#btnMoreEnquiriesSELink').click(callEnquiry);
But this doesn't look like good design, binding two pages so closely. Especially since you depend on enquiry loading within fixed time. Better would be to send (via query parameter?) some flag that will check if #h2 needs to be checked.
Something like this:
$(".btnMPPopUpLeft").on("load", "#h2", function() {
$( "#h2" ).attr( "checked", "checked" );
});
Finally, last two options
- if you have to set it always, why not just have checked="true" in HTML?
- I'm no PHP expert, but it seems to be that your PHP should set checked...not outside javascript...if I read your code correctly, you loop through number of elements which set either "CHECKED" or "" for the condition...but you never return...shouldn't that result in the control like this:
<input type="checkbox" name="type[]" value="content-text" id="h2" class="checkbox" CHECKBOXCHECKBOX
/>
for two content-text controls?
Also note that you're not closing the div.
Please check the html of your page WITHOUT javascript function. Also, use developer tools in the browser (even IE has some) and check console to see if your function gets called. Finally,in your function you can set console.log("message") ; to see what gets called...