Hi, I'm currently applying the autosave code i've got on the internet unfortunately I can't make it work. Below is the error encountered as well as the code being used.


Error Encountered:

Line: 4568
Char: 21
Error: Object Expected


Code being used:

<script  type="text/javascript">

pollingInterval = 5000;

threadLock = false;

saveMessage = "saved"

 function timeoutHandler(){

            clearTimeout(SaveTimeout);

            SaveTimeout = setTimeout("autosave()",pollingInterval);

}

function autosave(){

            var changes = checkFormChanged(document.%formname);

 

            if (changes && !threadLock) {

                        threadLock = true;

                        

    if ("%page" == "EP_APPR_BASE1")

                           $('input[@name=ICAction]').attr({value: 'EP_BTN_LINK_WRK_EP_STORE_PB'});

                        else

                           $('input[@name=ICAction]').attr({value: 'EP_BTN_LINK_WRK_EP_STORE_PB$19$'});

 

                        update_defaults(document.%formname);

 

                        var params = $('form[@name=%formname]').fastSerialize();

    $.ajax({ type: "POST", 

                                                 url: $('form[@name=%formname]').attr("action"), 

                                                 data: $.param( params ), 

                                                 dataType: "xml", 

                                                 success: 

                                                                                    function(msg, msg2)

                                                                                    { 

                                                                                                $('input[@name=ICChanged]').attr({value: '0'});

 

                                                                                    var searchFor = "'ICStateNum' value='";

                                                                                    var stateNumStart = msg.responseText.indexOf(searchFor) + searchFor.length;

                                                                                    var stateNumEnd = msg.responseText.indexOf("'", stateNumStart);

                                                                                    var newState = msg.responseText.substr(stateNumStart, stateNumEnd - stateNumStart);

                                                          $('input[@name=ICStateNum]').attr({value: newState});                                                                                 

                                                                                    display_notification();

            

                                                                                                            SaveTimeout = setTimeout ( "autosave()", pollingInterval );

                                                          

                                                          var SearchFor = null;

                                                          var stateNumStart = null;

                                                          var stateNumEnd = null;

                                                                                                            threadLock = false;

                                                                        }

                                    });

                                    }

                                    else

                                    {

                        SaveTimeout = setTimeout ( "autosave()", pollingInterval);

                                    };

};

 

function start_autosave(){

                        if ("%PAGE" == "EP_APPR_MAIN1" || "%PAGE" == "EP_APPR_BASE1")

                                    

                    if ($('input[@name=ICChanged]').val() != 0){

                                                SaveTimeout = setTimeout ( "autosave()", 1);

                                                }

                                                else

                                                {

                                                            SaveTimeout = setTimeout ( "autosave()", pollingInterval );

                                                }

            $('body').keypress(timeoutHandler);

 

            submitAction_%Formname = function(form, name){

 

                        form = $('form')[0];

                        $('body').css({cursor: "wait"});

                        function submit_the_form()

                        {

                                    form.ICAction.value=name;

                                    form.ICXPos.value=getScrollX();

                                    form.ICYPos.value=getScrollY();

                                    processing_%Formname(1,3000);

                                    form.ICResubmit.value=nResubmit;

                                    form.submit();

                                    nResubmit++;

                        }

                        function check_for_lock()

                        {

                                    if (threadLock){

                                                setTimeout("submitAction_%Formname('" + %formname + "','" + name + "')",250);

                                    }

                                    else{

                                                submit_the_form();

                                    }

                        }

                        check_for_lock();

            };

};

function addLoadEvent(func) {

  var oldonload = window.onload;

  if (typeof window.onload != 'function') {

    window.onload = func;

  } else {

    window.onload = function() {

      if (oldonload) {

        oldonload();

      }

      func();

    }

  }

};

 

if ("%page" == "EP_APPR_MAIN1" || "%page" == "EP_APPR_BASE1")

{

addLoadEvent(start_autosave);

};

</script>

Server side code has no place in the Javascript code, you should take a look at the generated code to pinpoint your problem. Use tools like the Error Console of Firefox and Firebug to debug your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.