Link to home
Start Free TrialLog in
Avatar of Enflow
EnflowFlag for United States of America

asked on

JavaScript Validation of Empty/Filled Shopping Cart

live web page with error: http://ebuildingpermits.com/California/Alameda-County-California-Building-Permit-Leads-Orig.aspx

JavaScript file... www.ebuildingpermits.com/subscribe/ccabpl2.js

// info passed by Refresh User Info
var xmlHttp;

function GetXmlHttpObject() {
    var objXMLHttp = null;
    // code for Mozilla, etc.          
    if (window.XMLHttpRequest) {
        objXMLHttp = new XMLHttpRequest();
    }
    // code for IE
    else if (window.ActiveXObject) {
        try {
            objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP")
        }
        catch (e) {
            objXMLHttp = new ActiveXObject("Msxml.XMLHTTP")
        }
        //objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP"); // Msxml  
    }
    return objXMLHttp;
}

function sendRequest(params, handler) {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Sorry - But Your Web Browser Does Not Support Our Shopping Cart - Please Call Us: 831-649-4659 To Order")
        return
    }

    xmlHttp.onreadystatechange = handler;
    xmlHttp.open("POST", document.forms[0].action)
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(params);
}

function testvalue() {
    var mytext = document.ShopForm.AreaSelected.options[document.ShopForm.AreaSelected.selectedIndex].text;
    var myvalue = document.getElementById("AreaSelected").value;
    //alert(myvalue)

    if (mytext == "Please Select A Subscription Type") {
        alert("You Forgot To Select A Subscription Type From The Drop Down Select Box");
        return false;
    }
    else {

        var params = "value=" + myvalue + "&id=" + Math.random();
        sendRequest(params, testvalueStateChanged);

        return false;
    }
}

function testvalueStateChanged() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        if (xmlHttp.responseText != "") {
            alert("Your New Subscription has been added to your Shopping Cart...");
        }
    }
}

function checkout() {

    var params = "checkout=1";
    sendRequest(params, checkoutStateChanged);

    return false;
}

function checkoutStateChanged() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        var ShopID = xmlHttp.responseText;
        //alert(ShopID)
        if (ShopID != "" && ShopID != "<br/>")
            window.location = "https://www.ebuildingpermits.com/Subscribe/SubscribeEM.aspx";
        else
            alert("Checkout - Why? - No Subscription Items Are In Your Shopping Cart...");
    }
}


The checkout function is NOT working right... It is supposed to test whether the database has an order in it or not (Shopping Cart is Filled or Empty)

The checkout() Function is called when a user clicks on the Proceed To Checkout button

<asp:Button ID="ProceedToCheckout" onClientClick="checkout()" runat="server" style="background-image: url(../Pics/Gifs/CheckOut.gif); background-repeat: no-repeat;" BackColor="Transparent" BorderStyle="None" ForeColor="Transparent" Height="42px" Width="215px" />

the Proceed to Checkout button is on this live page...

http://ebuildingpermits.com/California/Alameda-County-California-Building-Permit-Leads-Orig.aspx

and a JavaScript Alert pops up for a split second with the text "Checkout - Why? - No Subscription Items Are In Your Shopping Cart..."

WHETHER OR NOT THE CART IS FILLED OR EMPTY and then vanishes... which its not supposed to do...

I am confused as to how this JavaScript tests for an order in the database using the xmlHttp method so if i am a wee bit confusing or off the mark on my explanation please understand...

this WAS WORKING for years but now that the https SSL page gets a different Session ID then the regular non https SSL pages so this no longer works... i think or think incorrectly

I need help fixing this or putting in new JS code that tests for a order in the database exsits before the user will be allowed to go to the checkout page... or not allowed to go to the checkout page and an alert pops up telling them their is nothing in their cart... as i have

thanks... Cj
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Enflow

ASKER

Hi Gary... :o)

Mama Mia... worked right out the gate... !

Super Duper... NOW... a minor issue... ?

I can understand we had the syntax wrong and should have had return false in the right areas... ok.... that was perfect fix... but...

But HOW DOES THIS CHECK that their is a item in the shopping cart OR NOT... ???

How is it doing that ??

cause it is... check it for your self...

add no subscription and try to go to checkout and you correctly get the Why ? alert...

but when you DO ADD a SUB then it allows you into the checkout page... how does it know there is or is not an item in the cart.. .?

you can even DELETE the item from the shopping cart on the checkout page and go back button and then again click on the Proceed to Checkout button and correctly GET the Why ? alert...

so ?

thanks... Cj
Did you not write the code?
When you click the checkout button it does a post request, the response contains anything then it allows you to proceed, if the response is empty then it stops you going to the checkout page.
Avatar of Enflow

ASKER

We wrote all of aspx code and a bit of the JS code... but not the request/response checkout code...

thanks for the speed and clarity... awarded full points... to you... CJ
Avatar of Enflow

ASKER

very clear and very nice to work with GaryC123