Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7076311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:16:59+00:00 2026-05-28T06:16:59+00:00

This code works only if I reload/refresh page, otherwise it doesn’t work, I susspect

  • 0

This code works only if I reload/refresh page, otherwise it doesn’t work, I susspect issue is, because I use Jquery + normal javascript.

I have form and there is input which uses autocomplete, but while you go trough form next, it doesn’t work.

The point is that input with #SchoolName isn’t on first page is on 2nd page (after showcart(); function is trigered)…

Anyone have any ideas why my jquery code doesn’t load properly?

I have this code:

<script type="text/javascript" language="javascript">
    function autocomplete() {
        $("#SchoolName").autocomplete("ajaxFuncs.php", {
            cacheLength:1,
            mustMatch:1,
            extraParams: {getSchoolName:1}
        });
    };

    $(document).ready(function(){
        setTimeout("autocomplete()", 500);
    });

    function showVal(str) {
        if (str == "") {   
            document.getElementById("txtHint").innerHTML = "* Please type in School Name.";
            return;
        }
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  
        }

        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) { // break this into 2 statements so you can handle HTTP errors
                document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
                } else {
                document.getElementById("txtHint").innerHTML = "AJAX Error (HTTP "+xmlhttp.status+")";
                }
            }
        }; // functions declared in this way should be followed by a semi colon, since the function declaration is actually a statement.

        // encodeURIComponent() does all the escaping work for you - it is roughly analogous to PHP's urlencode()
        // xmlhttp.open("GET","ajaxFuncs2.php?q="+encodeURIComponent(str),true);

        xmlhttp.open("GET","ajaxFuncs2.php?q="+encodeURIComponent(str),true);
        xmlhttp.send();
    }
</script>



<script>
    function ajax(doc)
    {
        doc = null;
        if (window.XMLHttpRequest) {
            try {
                doc = new XMLHttpRequest();
            }
            catch(e) {
                if(SBDebug) 
                    alert("Ajax interface creation failure 1");
            }
        }
        else if (window.ActiveXObject) {
            try {
                doc = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e) {
                try {
                    doc = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e) {
                    if(SBDebug)
                        alert("Ajax interface creation failure 2");
                }
            }
        }
        return doc;
    }



    function postIt(params) {
        var doc;
        // alert("postIt: " + params);  

        if(params == "")
            params = "nada=0";

        doc = ajax(doc);

        if (doc) {
            var url = window.location.href;
            url = url.substr(0, url.lastIndexOf("/") + 1) + "clientCartPost.php";

            // alert(url);
            doc.open("POST", url, false);

            //Send the proper header information along with the request
            doc.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            doc.setRequestHeader("Content-length", params.length);
            doc.setRequestHeader("Connection", "close");

            document.body.style.cursor = "wait";
            doc.send(params);
            document.body.style.cursor = "default";

            if(doc.responseText == "timeout") {
                alert("Timed out");
                document.location = "index.php";
            }
            return doc.responseText;
        }
        return "Connection Failed";
    }





    function saveCC() {
        var doc;
        doc = ajax(doc);

        if(params == "")
        params = "nada=0";

        if (doc) {
            var params = "";
            var eVisi = document.getElementById("visiCard");
            var eCard = document.getElementById("x_card_num");

            if(eVisi.value.indexOf("*") < 0)
                eCard.value = eVisi.value;

            for(i=0; i<document.CC.elements.length; i++) {
                if(document.CC.elements[i].name == "visiCard")
                    continue;

                params += getElemValue(document.CC.elements[i]) + "&";
            }

            doc.open("POST", "https://dot.precisehire.com/clientCartStoreCard.php", false);

            //Send the proper header information along with the request
            doc.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            doc.setRequestHeader("Content-length", params.length);
            doc.setRequestHeader("Connection", "close");

            document.body.style.cursor = "wait";
            doc.send(params);
            document.body.style.cursor = "default";

            // alert(doc.responseText);
            return true;
        }
        return false;
    }



    function getElemValue(item)

    {

    // alert("Getting: " + itemBase + itemID);

    // alert(itemBase + "" + itemID);

        if(item.type == "radio" || item.type == "checkbox")

        {

            if(!item.checked)

                return "";

        }

        if(item.type == "select-one")

        {

            value = item.options[item.selectedIndex].value;

        }

        else

            value = item.value;

        return item.name + "=" + escape(value) + "&";

    }



    function    makePie()

    {

        var contents = postIt("command=getProgress");



        document.getElementById("step2").className = "bx2";

        document.getElementById("step3").className = "bx2";

        document.getElementById("step4").className = "bx2";

        if(contents > 0)

            document.getElementById("step2").className = "bx1";

        if(contents > 1)

            document.getElementById("step3").className = "bx1";

        if(contents > 2)

            document.getElementById("step4").className = "bx1";

    }



    var gbColor;



    function    RedIn(start)

    {

        var id;



        if(start)

            gbColor = 0;

        gbColor += 32;

        if(gbColor > 255)

            gbColor = 255;

        id = 0;

        var obj = document.getElementById("red" + id);

        while(obj != undefined)

        {

            obj.style.backgroundColor = 'rgb(255,' + gbColor + ',' + gbColor + ')'; 

            id++;

            obj = document.getElementById("red" + id);

        }

        if(gbColor < 255 && id > 0)

            setTimeout("RedIn(0)", 100);

    }



    function    showCart(next)

    {

        var ca = document.getElementById("cartArea");

        var params = "";



        for(i=0; i<document.clientCart.elements.length; i++)

        {

            param = getElemValue(document.clientCart.elements[i]);

            if(param != "")

                params += param + "&";

        }

        if(next)

            params += "Next=1";

    // alert(params);

        ca.innerHTML = postIt(params);



        makePie();

    //  RedIn(1);

    }



    function    tabIfComplete(formField, maxSize, nextField, e)

    {

        if(window.event) // IE

        {

            keynum = e.keyCode;

        }

        else if(e.which) // Netscape/Firefox/Opera

        {

            keynum = e.which;

        }

        if(keynum < 48)

            return;

        if(formField.value.length >= maxSize)

        {

            var nf = document.getElementById(nextField);



            if(nf)

                nf.focus();

        }

    }



    function    sendCommand(command)

    {

        var ca = document.getElementById("cartArea");

        var params = "command=" + command;

        var submitOrder = command.indexOf('submitOrder') >= 0;

    // alert(command);

        if(submitOrder)

        {

            if(document.getElementById("RESULT").checked)

            {

                params += "&postSettlement=result";

    /*

                n = postIt(params);

                alert(nOID);

                if(nOID > 0)

                    document.location="orderreview.php?id=" + nOID;

                return;

    */

            }

            else if(document.getElementById("REPORT").checked)

            {

                params += "&postSettlement=report";

            }

            else if(document.getElementById("DUPEORDER").checked)

            {

                params += "&postSettlement=dupeorder";

            }

            postIt(params);

            document.location="cart.php";

            return;

        }

        else if(command.indexOf('priorSearches') >= 0)

        {

            document.location="orderreview.php?ssnlist=1";

        }

        else if(command.indexOf('addState') >= 0)

        {

            for(i=0; i<document.clientCart.elements.length; i++)

            {

                if(document.clientCart.elements[i].name != "Next")

                    params += "&" + getElemValue(document.clientCart.elements[i]);

            }

        }

        ca.innerHTML = postIt(params);

        makePie();

    }



    function    doReset()

    {

        var ca = document.getElementById("cartArea");



        ca.innerHTML = "";

        ca.innerHTML = postIt("reset=1");

        makePie();

    }



    function    dupeOrder()

    {

        var ca = document.getElementById("cartArea");



        ca.innerHTML = "";

        ca.innerHTML = postIt("dupeOrder=1");

        makePie();

    }



    function    resetCart()

    {

        if(confirm("Empty current cart and start over? Are you Sure?"))

            doReset();

    }



    function    saveCart()

    {

        var ca = document.getElementById("cartArea");

        var params = "";



        for(i=0; i<document.clientCart.elements.length; i++)

        {

            params += getElemValue(document.clientCart.elements[i]) + "&";

        }

        params += "saveExit=1";

        ca.innerHTML = postIt(params);

        makePie();

        RedIn(1);

    }



    function    deleteOrderItem(command)

    {

        if(!confirm("Delete this search? Are you Sure?"))

            return;



        var ca = document.getElementById("cartArea");

        var params = "command=" + command;



        ca.innerHTML = postIt(params);

        makePie();

    }



    // alert("Reloaded");



    setTimeout("showCart();", 100);

</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:16:59+00:00Added an answer on May 28, 2026 at 6:16 am

    Try to move the last line:

    setTimeout("showCart();", 100);
    

    …into the $.ready-function:

    $(document).ready(function(){
        setTimeout("autocomplete()", 500);
    });
    

    Otherwise it may happen that showCart() gets called before the elements you access in showCart() are known.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was using this code to reload the page, however I'd only tested it
I have the following code in a shell script. This only seems to work
This bit of code used to work, and now it doesn't: var url =
This code works (C# 3) double d; if(d == (double)(int)d) ...; Is there a
This code works fine: $result = $client->__call(optionalInfo, array( new SoapParam(..., client), new SoapParam(..., add_code))
This code works, but i dont understand why. With DeferredLoadingEnabld = false, I would
This code works in a windows forms application (it shows the preview) but not
This code works correctly to make a web service call: int numberOfGuests = Convert.ToInt32(search.Guest);
This code works: monkey.h @interface monkey : NSObject { NSNumber *monkeyRanch; } @property (nonatomic,
This code works (when ControlType=dropDown then the background yellow ): <Window x:Class=TestCollapsed.Views.MainView xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.