Welcome Guest, Not a member yet? Register   Sign In
jQuery and CI together
#1

[eluser]Unknown[/eluser]
I have created the MVC files, and a helper file to load the jquery libraries,

however, when i try to display my view, nothing happens,

what could possibly missing, do i have to configure something,? does jquery doesn't work exactly as it was when your doing plain html,

what i am just trying to accomplish is to display a timer, i already have the function timer, however, when i try to load it, nothing happen, nothing is displayed,

timer.js
Code:
function formatTime() {
    now = new Date();
    hour = now.getHours();
    min = now.getMinutes();
    sec = now.getSeconds();
  
    if (min <= 9) {
        min = "0" + min;
    }
    if (sec <= 9) {
        sec = "0" + sec;
    }
    if (hour > 12) {
        hour = hour - 12;
        add = " PM";
    } else {
        hour = hour;
        add = " AM";
    }
    if (hour == 12) {
        add = " PM";
    }
    if (hour == 00) {
        hour = "12";
    }
    
    var ttime=((hour<=9) ? "0" + hour : hour) + ":" + min + ":" + sec + add;
    setTimeout("formatTime()", 1000);
    $("#divHeader").html(ttime);
}

on the load of view.php

Code:
$(window).load(formatTime());

i tried everything, like just putting the same code in the view.php, putting it outside an external js file, im almost buried here... any help or insights is appreciated,

Thanks,
#2

[eluser]TheCore[/eluser]
Hello, Please try the following code

timer.js

Code:
function formatTime() {
    now = new Date();
    hour = now.getHours();
    min = now.getMinutes();
    sec = now.getSeconds();
  
    if (min <= 9) {
        min = "0" + min;
    }
    if (sec <= 9) {
        sec = "0" + sec;
    }
    if (hour > 12) {
        hour = hour - 12;
        add = " PM";
    } else {
        hour = hour;
        add = " AM";
    }
    if (hour == 12) {
        add = " PM";
    }
    if (hour == 00) {
        hour = "12";
    }
    
    var ttime=((hour<=9) ? "0" + hour : hour) + ":" + min + ":" + sec + add;
        $("#divHeader").html(ttime);

    
    setTimeout("formatTime()", 1000);
}


paste the following code on your view page


Code:
$(document).ready(function(){
         formatTime();
    })
#3

[eluser]Unknown[/eluser]
Quote:Make sure the view page loaded the jquery library successfully

how do i check if it loads properly? honestly this is what i am suspecting... is there a way to check if its loaded?

thanks,
#4

[eluser]TheCore[/eluser]
Load the page in your browser, right click and view the source code, Click on the jquery path showing on the source code, if its load successfully you can make sure your page has jquery or simple write the following code on the view page inside script tags

Code:
$(document).ready(function(){
        alert('jquery loaded');
    })

Hope this will help you
#5

[eluser]byde[/eluser]
try using $(document).ready(function(){ }) ; function in your js and your view.php
#6

[eluser]InsiteFX[/eluser]
Code:
$(document).ready(function(){
         formatTime();
    });  // <-- missing semi-colon

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB