jeudi 13 août 2015

Javascript Checking for checkboxes from a processor page

So... To make along story short... I am checking a checkbox, clicking a button and printing labels out of my Zebra printer.

I am using processor pages to do certain things, here is an example of the javascript function:

<input type="button" name="doit" value="Go ->" style="cursor:hand;" class="normal" onMouseOver="this.style.color='orangered';" onMouseOut="this.style.color='black';" onClick="document.frmMain.classs.value = document.frmMain.classes.value; getLocationsTable();">

So when I click Go, I will then make the table... and this is my getLocationsTable:

function getLocationsTable(){

        // Create the variables.
        var elLocationsTable;
        var elClass;
        var elLocation;
        var elActiveOnly;
        var strURL;
        var iActive;

        // Initialize the variables.
        elLocationsTable = document.getElementById('locationstable')
        elClass = document.frmMain.classs;
        elLocation = document.frmMain.location;
        elActiveOnly = document.frmMain.activeonly;
        strURL = '';
        iActive = 0;
        xmlHTTP1 = null;

        // Get an xmlHTTPRequest object.  Jump out with an error if the object can't be created.
        xmlHTTP1 = getXMLHTTPObject();
        if(xmlHTTP1 == null){
            alert("Your browser does not support AJAX!");
            return;
        }


        // Clear the table of it's current contents.
        elLocationsTable.innerHTML = strLoadingImgTable;

        // If the 'active only' checkbox is checked, ...
        if(elActiveOnly.checked)
            iActive = 1;

        // Contruct the URL.
        strURL = './processors/getLocationsTable.asp?classs=' + elClass.value + '&location=' + elLocation.value + '&active=' + iActive + '&id=' + Math.random();

        // Setup the xmlHTTP object, open it & send the request.
        xmlHTTP1.onreadystatechange = displayLocationsTable;
        xmlHTTP1.open("GET", strURL, true);
        xmlHTTP1.send(null);

    }

    function displayLocationsTable(){
        if(xmlHTTP1.readyState == 4){

            // Create the variables.
            var elLocationsTable;

            // Initialize the variables.
            elLocationsTable = document.getElementById('locationstable')


            // Display the table.
            elLocationsTable.innerHTML = xmlHTTP1.responseText;

        }
    }

So, here is the getLocationsTable.asp page:

strPageName = "getPartsTable.asp"
Server.ScriptTimeout = 600

' modify connection timeout.
conWMS.CommandTimeout = 600


' Set up the query.
strSQL = "SELECT a.location, shelf, ISNULL(a.description, '') AS 'description', a.depth, a.status, a.class, b.description AS 'description2', " & _
         "ISNULL(a.crossdock, 0) AS 'crossdock', last_count, cc_required, a.active " & _
         "FROM wms_locations AS a LEFT OUTER JOIN wms_classes AS b ON a.class = b.class "
If Len(Request("location")) = 0 Then
    If Len(Request("classs")) > 0 Then
        strSQL = strSQL & "WHERE a.class = '" & Request("classs") & "' "
    Else
        strSQL = strSQL & "WHERE b.description IS NULL "
    End If
    If CInt(Request("active")) = 1 Then
        strSQl = strSQL & "AND a.active = 1 "
    End If
Else
    strSQL = strSQL & "WHERE a.location LIKE '%" & Request("location") & "%' "
End If
strSQL = strSQL & "ORDER BY a.location"
Set rsTemp = conWMS.Execute(strSQL)


strTemp = "<table width='100%' align='center' cellpadding='3' cellspacing='0' border='0'>"
    strTemp = strTemp & "<tr>"
        strTemp = strTemp & "<td align='left' valign='bottom' nowrap colspan='7' class='bodyText'>"
            strTemp = strTemp & "<table width='65%' align='left' cellpadding='1' cellspacing='0' border='0' style='border: 1px solid orangered;'>"
                strTemp = strTemp & "<tr>"
                    strTemp = strTemp & "<td width='5%' align='right' valign='middle' nowrap class='bodyText6'><span style='font-weight: bold; color: red;'>Note:</span></td>"
                    strTemp = strTemp & "<td align='left' valign='middle' nowrap class='bodyText6'> - Click in a cell to edit it's contents.</td>"
                strTemp = strTemp & "</tr>"
            strTemp = strTemp & "</table>"
        strTemp = strTemp & "</td>"
        strTemp = strTemp & "<td align='right' valign='bottom' colspan='2' nowrap class='bodyText'>"
            strTemp = strTemp & "<input type='button' name='locationssetup' value='Refresh Table' style='font-size: 8; cursor: hand;' class='bodyText' onMouseOver='this.style.color=""orangered"";' onMouseOut='this.style.color=""black"";' onClick='getLocationsTable();'></input>"
        strTemp = strTemp & "</td>"
        strTemp = strTemp & "<td align='right' valign='bottom' colspan='2' nowrap class='bodyText6'>"
            strTemp = strTemp & "<input type='radio' name='labelsize' value='2x3' style='cursor:hand;'>2x3 Labels</input><br><input type='radio' name='labelsize' value='4x6' checked style='cursor:hand;'>4x6 Labels</input><br>"
            strTemp = strTemp & "<input type='button' name='printlabels' value='Print Labels' style='cursor:hand;' class='bodyText6' onMouseOver='this.style.color=""orangered"";' onMouseOut='this.style.color=""black"";' onClick='if (!confirm(""Do you have the correct size labels in the printer?"")) return false; if (document.frmMain.printlist.value.length == 0) {alert(""No Locations Selected!""); return false;}  else {printLocationLabels();}'></input>"
        strTemp = strTemp & "</td>"

    strTemp = strTemp & "</tr>"
    strTemp = strTemp & "<tr style='background-color: darkorange; font-weight: bold;'>"
        strTemp = strTemp & "<td align='left' valign='bottom' nowrap class='bodyTextTL'>Location</td>"
        strTemp = strTemp & "<td align='center' valign='bottom' nowrap class='bodyTextTL'>Shelf</td>"
        strTemp = strTemp & "<td align='center' valign='bottom' nowrap class='bodyTextTL'>Description</td>"
        strTemp = strTemp & "<td align='center' valign='bottom' nowrap class='bodyTextTL'>Depth</td>"
        strTemp = strTemp & "<td align='center' valign='bottom' nowrap class='bodyTextTL'>Status</td>"
        strTemp = strTemp & "<td align='center' valign='bottom' nowrap class='bodyTextTL'>Class <span style='font-size:10;'>(class description)</span></td>"
        strTemp = strTemp & "<td align='center' valign='bottom' nowrap class='bodyTextTL'>Crossdock</td>"
        strTemp = strTemp & "<td align='center' valign='bottom' nowrap class='bodyTextTL'>Last<br>Cycle Count</td>"
        strTemp = strTemp & "<td align='center' valign='bottom' nowrap class='bodyTextTL'>CC<br>Priority<br><span style='font-size:8px;'>(1 - 10)</span></td>"
        strTemp = strTemp & "<td align='center' valign='bottom' nowrap class='bodyTextTL'>Active</td>"
        strTemp = strTemp & "<td align='center' valign='bottom' nowrap class='bodyTextTLR'>Print<br>Label</td>"
    strTemp = strTemp & "</tr>"

    If rsTemp.EOF Then

        strTemp = strTemp & "<tr height='35'>"
            strTemp = strTemp & "<td align='center' valign='middle' colspan='11' nowrap style='font-weight: bold;'class='bodyTextTLR'>No Data Found</td>"
        strTemp = strTemp & "</tr>"
        strTemp = strTemp & "<tr>"
            strTemp = strTemp & "<td align='center' valign='middle' nowrap colspan='11' style='font-weight: bold;' class='bodyTextT'>&nbsp</td>"
        strTemp = strTemp & "</tr>"

    Else

        Do While Not rsTemp.EOF
            strActive = "Active"
            If rsTemp("active") = 0 Then
                strActive = "Dormant"
            End If
            strTemp = strTemp & "<tr>"
                strTemp = strTemp & "<td align='left' valign='middle' nowrap class='bodyTextTL'>" & Trim(rsTemp("location")) & "&nbsp</td>"
                strTemp = strTemp & "<td align='left' valign='middle' nowrap style='cursor:hand;' class='bodyTextTL' onMouseOver='this.style.color=""red"";' onMouseOut='this.style.color=""black"";' onClick='updateLocationsTable(""" & rsTemp("location") & """,""" & rsTemp("shelf") & """, ""shelf"", 2);'>" & Trim(rsTemp("shelf")) & "&nbsp</td>"
                strTemp = strTemp & "<td align='left' valign='middle' nowrap style='cursor:hand;' class='bodyTextTL' onMouseOver='this.style.color=""red"";' onMouseOut='this.style.color=""black"";' onClick='updateLocationsTable(""" & rsTemp("location") & """,""" & rsTemp("description") & """, ""description"", 101);'>" & Trim(rsTemp("description")) & "&nbsp</td>"
                strTemp = strTemp & "<td align='center' valign='middle' nowrap style='cursor:hand;' class='bodyTextTL' onMouseOver='this.style.color=""red"";' onMouseOut='this.style.color=""black"";' onClick='updateLocationsTable(""" & rsTemp("location") & """, """ & rsTemp("depth") & """, ""depth"", 2);'>" & Trim(rsTemp("depth")) & "&nbsp</td>"
                strTemp = strTemp & "<td align='left' valign='middle' nowrap style='cursor:hand;' class='bodyTextTL' onMouseOver='this.style.color=""red"";' onMouseOut='this.style.color=""black"";' onClick='updateLocationsTable(""" & rsTemp("location") & """, """ & rsTemp("status") & """, ""status"", 1);'>" & Trim(rsTemp("status")) & "&nbsp</td>"
                strTemp = strTemp & "<td align='left' valign='middle' nowrap style='cursor:hand;' class='bodyTextTL' onMouseOver='this.style.color=""red"";' onMouseOut='this.style.color=""black"";' onClick='updateLocationsTable(""" & rsTemp("location") & """, """ & rsTemp("class") & """, ""class"", 31);'>" & Trim(rsTemp("class")) & " <span style='font-size:10;'>(" & Trim(rsTemp("description2")) & ")</span>&nbsp</td>"
                strTemp = strTemp & "<td align='right' valign='middle' nowrap style='cursor:hand;' class='bodyTextTL' onMouseOver='this.style.color=""red"";' onMouseOut='this.style.color=""black"";' onClick='updateLocationsTable(""" & rsTemp("location") & """, """ & rsTemp("crossdock") & """, ""crossdock"", 2);'>" & Trim(rsTemp("crossdock")) & "&nbsp</td>"
                strTemp = strTemp & "<td align='right' valign='middle' nowrap class='bodyTextTL'>" & Trim(rsTemp("last_count")) & "&nbsp</td>"
                strTemp = strTemp & "<td align='right' valign='middle' nowrap style='cursor:hand;' class='bodyTextTL' onMouseOver='this.style.color=""red"";' onMouseOut='this.style.color=""black"";' onClick='updateLocationsTable(""" & rsTemp("location") & """,""" & rsTemp("cc_required") & """, ""cc_required"", 2);'>" & rsTemp("cc_required") & "&nbsp</td>"
                strTemp = strTemp & "<td align='center' valign='middle' nowrap style='cursor:hand;' class='bodyTextTL' onMouseOver='this.style.color=""red"";' onMouseOut='this.style.color=""black"";' onClick='changeLocationStatus(""" & rsTemp("location") & """, """ & rsTemp("active") & """);'>" & strActive & "&nbsp</td>"
                    strTemp = strTemp & "<td align='center' valign='center' nowrap class='bodyTextTLR'>"
                        'strTemp = strTemp & "<input type='checkbox' name='" & rsTemp("location") & "~" & rsTemp("shelf") & "' style='cursor:hand;' class='bodyText' onClick='buildPrintList();'></input>"
                        strTemp = strTemp & "<input type='checkbox' name='" & rsTemp("location") & ":" & rsTemp("shelf") & "' style='cursor:hand;' class='bodyText' onClick='buildPrintList();'></input>"
                    strTemp = strTemp & "</td>"
            strTemp = strTemp & "</tr>"
            rsTemp.MoveNext
        Loop

        strTemp = strTemp & "<tr>"
            strTemp = strTemp & "<td align='right' valign='middle' colspan='11' nowrap style='font-size: 10; font-weight: bold;' class='bodyTextT'>&nbsp</td>"
        strTemp = strTemp & "</tr>"

    End If
    rsTemp.Close

    strTemp = strTemp & "</table>"


conWMS.Close
Set conWMS = Nothing

Response.Write(strTemp)

In there you can see I have this line:

strTemp = strTemp & "<input type='checkbox' name='" & rsTemp("location") & ":" & rsTemp("shelf") & "' style='cursor:hand;' class='bodyText' onClick='buildPrintList();'></input>"    

Which is just making the checkbox... So when they click on that checkbox... I am going to run buildPrintList()... (I want to use the commented out lines, but the lines above it is my way of testing what elements are on frmMain that are checkboxes type)

function buildPrintList(){

        // Create the variables.
        var frmMain;
        var elPrintList;
        var strTemp;
        var i;


        // Initialize the variables.
        //frmMain = document.frmMain;
        frmMain = document.getElementById('frmMain');
        elPrintList = frmMain.printlist;
        strTemp = '';
        i = 0;



        for (i=0; i<frmMain.elements.length; i++){
            if (frmMain.elements[i].type == 'checkbox'){
                alert(frmMain.elements[i].type + " " + frmMain.elements[i].name + " " + frmMain.elements[i].checked + " " + frmMain.elements[i].value );
            }
        }

        // Put together a list of serials to delete.
        //for (i=0; i<frmMain.elements.length; i++){
        //alert(frmMain.elements[i].type + " " + frmMain.elements[i].name + " " + frmMain.elements[i].checked + " " + frmMain.elements[i].value );
        //  if (frmMain.elements[i].type == 'checkbox' && frmMain.elements[i].name != 'activeonly'){            
        //      if (frmMain.elements[i].checked)

        //          strTemp = strTemp + frmMain.elements[i].name + ',';
        //  }
        //}

        // Clean up the list.
        if (strTemp.length > 0)
            strTemp = strTemp.substr(0, strTemp.length-1);

        // Save the delete list to a element.
        elPrintList.value = strTemp;

    }

And this is where my problem occurs... For whatever reason, when I use that secondary page to write the html for the table... It does not consider those checkboxes to be a part of frmMain... Because when I run my little testing code I only get this...

checkbox activeonly true 1

Anybody have any idea what is going on here? Please don't downvote me without telling me why you did... If you need more information please just ask.




Aucun commentaire:

Enregistrer un commentaire