Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

JS: Function not working

  • 22-04-2015 9:02am
    #1
    Registered Users, Registered Users 2 Posts: 1,469 ✭✭✭


    For some weird reason my function isn't working and I was wondering what im missing, I'll try to explain.

    When you first load the website it needs to load a function, after this it will start loading into divs.

    Code in my div (Also tried: body onload or in the header)
    <script type="text/javascript">
    <?php  
    if(empty($write_page['1'])) { 
    ?>
    loadthisframe(home);
    <?php 
    }             
    else         
    { 
    ?>
    var <?php echo $write_page['1']; ?>;
    loadthisframe(<?php echo $write_page['1']; ?>);
    <?php
    } 
    ?>
    </script>
    

    So i stripped down the complete function to test:
    function loadthisframe(loadthisframe) {
        console.log("load page");
    }
    

    The code above will display something like:
    <script type="text/javascript">
    loadthisframe(home);
    </script>
    

    or
    <script type="text/javascript">
    var contact;
    loadthisframe(contact);
    </script>
    

    This is based on what page you are at,



    But it doesn't work, when I delete the "var <?php echo $write_page; ?>;"

    I get the following: "ReferenceError: home is not defined"

    The rest of the website works fine, its not that its waiting for jquery or so..



    When i click on a existing tab, which does the same (kinda), works fine.
    $('#tabhome').bind('click', function(event) {
    var home = "home";	
    loadpageframe(home);
    window.history.pushState("object or string", "Title", "/");
    });
    


    I also tried replacing loadthisframe with loadpageframe but there is where the problem started so i'm trying to strip down till i find the issue.






    Update 11:42, I updated the load code to:
    <script type="text/javascript">
    window.onload = function(){
    <?php  
    if(empty($write_page['1'])) { 
    ?>
    var home = "home";
    loadthisframe(home);
    <?php 
    } 			
    else 		
    { 
    ?>
    var <?php echo $write_page['1']; ?> = "<?php echo $write_page['1']; ?>";
    loadthisframe(<?php echo $write_page['1']; ?>);
    <?php
    } 
    ?>
    }
    </script>
    

    and the function to:
    function loadthisframe(paged) {
    	var framed = paged;
    	console.log("loading page "+framed);
    	console.log("starting injecting frame "+framed);
    	loadpageframe(framed);
    }
    



    console.log output:

    ReferenceError: loadpageframe is not defined main.data.js:174:1
    "loading page home" main.data.js:172:1
    "starting injecting framehome" main.data.js:173:1


    So I replaced 'loadpageframe' by 'loadpageframe' for testing, giving output: ReferenceError: loadpageframe is not defined




    this is my loadpageframe:

    function loadpageframe(loadframe) {
    	var paged = loadframe;
    	console.log("/html/"+paged+".php");
    	$.ajax({
            type: "GET",
            url: "/html/"+paged+".php",
            cache: false,
    		beforeSend: function() { 
    			$("#wait").css("display", "block");
    			$('#dataincontent').html("&nbsp;");  
    			if(paged == "videos") {
    			$("#tabblog").removeClass('ui-btn-active');
    			$("#tabprojects").removeClass('ui-btn-active');				
    			$("#tabvideos").addClass('ui-btn-active');
    			} else if(paged == "blog") {
    			$("#tabblog").addClass('ui-btn-active');
    			$("#tabprojects").removeClass('ui-btn-active');				
    			$("#tabvideos").removeClass('ui-btn-active');
    			} else if(paged == "projects") {
    			$("#tabblog").removeClass('ui-btn-active');
    			$("#tabprojects").addClass('ui-btn-active');				
    			$("#tabvideos").removeClass('ui-btn-active');
    			}
    			else
    			{
    			$("#tabblog").removeClass('ui-btn-active');
    			$("#tabprojects").removeClass('ui-btn-active');				
    			$("#tabvideos").removeClass('ui-btn-active');
    			}
    		},
            success: function (data) { 
    			$('#dataincontent').html(data); 
    		},
            error: function (data) { 
    			$('#contentdata').html("ERROR"); 
    		},
    		complete: function() { 
    			$("#wait").css("display", "none"); 
    			$("#dataincontent").css("display", "inline-block"); 
    		}
        });
    }
    



    FIXED!

    Moved the code to another .js file for some reason it doesn't accept to be after onload which ofc is logic -_-


Advertisement