Javascript functions not working on second page of ajax'd paging

Discussion in 'JavaScript' started by snowboarder, Aug 6, 2006.

  1. #1
    The problem I am having is I have ajax paging implimented and I have 6+ javascript functions I want to preform on checkboxes etc... These javascript functions all work correctly when I am on the first page of the ajax'd paging, but when i goto the second one... the elements are considered undefined (i used an alert message to test it) I can't figure out why its doing this... I have done testing ... searched the web... but I can't figure out why the elements don't respond!!


    Here is the outputed ajax'd page... on page 2, the page I am having trouble with... below this code is the javascript I am running on it...

    (to many characters so i uploaded it in a text file)

    http://www.vzio.com/code.txt


    javascripts:

    
    // Make star
    
        function makestar(intstatus) {
        var datacollecting="";
        var cbCollection = document.forms['fmail'].elements['mailchecks'];
        for ( var i = 0; i < cbCollection.length; i++ ) {
            if ( cbCollection[i].checked ) {
                datacollecting = datacollecting + "&id=" + cbCollection[i].value;
            }
        }
             if ( datacollecting != "") {
                datacollecting = datacollecting + "&status=" + intstatus;
                dec = datacollecting.indexOf('&');
                tmp = datacollecting.substring(0,dec);
                tmp += datacollecting.substring(dec+1,datacollecting.length);
                datacollecting = tmp;
                var url2 = "/ajax/mail/save_stars.asp";
                xmlHttp=createRequestObject();
                xmlHttp.onreadystatechange = reportStatus;
                xmlHttp.open("POST",url2,true);
                xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
                xmlHttp.send(datacollecting);
             }
        }
    /////--->
    
    
    //mail status
        function statuschange(intstatus) {
        var datacollecting="";
        var cbCollection = document.forms['fmail'].elements['mailchecks'];
        for ( var i = 0; i < cbCollection.length; i++ ) {
            if ( cbCollection[i].checked ) {
                datacollecting = datacollecting + "&id=" + cbCollection[i].value;
            }
        }
             if ( datacollecting != "") {
                datacollecting = datacollecting + "&status=" + intstatus;
                dec = datacollecting.indexOf('&');
                tmp = datacollecting.substring(0,dec);
                tmp += datacollecting.substring(dec+1,datacollecting.length);
                datacollecting = tmp;
                var url2 = "/ajax/mail/mail_status.asp";
                xmlHttp=createRequestObject();
                xmlHttp.onreadystatechange = reportStatus;
                xmlHttp.open("POST",url2,true);
                xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
                xmlHttp.send(datacollecting);
             }
        }
    /////
    
    
    
    // check all mail
    function checkall() {
        var cbCollection = document.forms['fmail'].elements['mailchecks'];
        for ( var i = 0; i < cbCollection.length; i++ ) {
            if (cbCollection[i].checked==false) {
            cbCollection[i].checked=true;
            }
        }
    }
    
    
    // un-check all mail
    function uncheckall() {
        var cbCollection = document.forms['fmail'].elements['mailchecks'];
        alert(cbCollection.length);
        for ( var i = 0; i < cbCollection.length; i++ ) {
            if (cbCollection[i].checked==true) {
            cbCollection[i].checked=false;
            }
        }
    }
    
    
    // check all read mail
    function checkread() {
        var cbCollection = document.forms['fmail'].elements['mailchecks'];
        var cbReadCollection = document.forms['fmail'].elements['readx'];
        for ( var i = 0; i < cbReadCollection.length; i++ ) {
            if (cbReadCollection[i].value=="1") {
            cbCollection[i].checked=true;
            } else {
            cbCollection[i].checked=false;
            }
        }
    }
    
    
    
    // check all unread mail
    function checkunread() {
        var cbCollection = document.forms['fmail'].elements['mailchecks'];
        var cbReadCollection = document.forms['fmail'].elements['readx'];
        for ( var i = 0; i < cbReadCollection.length; i++ ) {
            if (cbReadCollection[i].value=="0") {
            cbCollection[i].checked=true;
            } else {
            cbCollection[i].checked=false;
            }
        }
    }
    
    
    
    // check all starred mail
    function checkstarred() {
        var cbCollection = document.forms['fmail'].elements['mailchecks'];
        var cbStarredCollection = document.forms['fmail'].elements['starx'];
        for ( var i = 0; i < cbStarredCollection.length; i++ ) {
            if (cbStarredCollection[i].value=="1") {
            cbCollection[i].checked=true;
            } else {
            cbCollection[i].checked=false;
            }
        }
    }
    
    
    
    // un-check all starred mail
    function uncheckstarred() {
        var cbCollection = document.forms['fmail'].elements['mailchecks'];
        var cbStarredCollection = document.forms['fmail'].elements['starx'];
        for ( var i = 0; i < cbStarredCollection.length; i++ ) {
            if (cbStarredCollection[i].value=="0") {
            cbCollection[i].checked=true;
            } else {
            cbCollection[i].checked=false;
            }
        }
    }
    
    
    Code (markup):

     
    snowboarder, Aug 6, 2006 IP