Search code examples
javascriptgoogle-chromemicrosoft-edgecoldfusion-10

Serial Number Box Wont Autofill Anymore


1Last year, Chrome made updates that blocks certain javascript from working properly. I have this working in Internet Explorer but it doesn't work in Firefox, Edge, or Chrome.

When selecting a specific Part, which is checked in pcpSelect variable, the Serial number correlated to that part will automatically display in the text box. But it is getting blocked now and I am having issues getting the DOM to work properly now. Does anyone have any suggestions? Here is a screenshot of the error after selecting part number from dropdown

function fillSerial()
{
    var pcpSelect = document.frm_CreatePCP.PCP_ID.selectedIndex;
    var PCP = document.frm_CreatePCP.PCP_ID(pcpSelect).value;
    //alert(PCP);
    for (var i = 1; i < PCP_array.length; i++) 
    {
        if ( PCP == PCP_array[i] )
            {
            document.frm_CreatePCP.sn.value = Number(Serial_array[i]) +1;
            document.frm_CreatePCP.sn.refresh;
            document.frm_CreatePCP.part.value=PCP;
            //document.getElementById("openserial").onclick="javascript:void window.open('selectExistSerial.cfm?pcp_id='+PCP+','1351625603240','width=300,height=150,resizable=1,left=650,top=300');" ;
            document.getElementById("openserial").disabled = false;
            break;
            
            }
    }
}

function openSerialWindow()
{
    var pcpSelect = document.frm_CreatePCP.PCP_ID.selectedIndex;
    var PCP = document.frm_CreatePCP.PCP_ID(pcpSelect).value;
    if (PCP.length < 1) {
        alert ("Part is required");
        document.frm_CreatePCP.PCP_ID.focus();
        }
    else
    {
    //alert(PCP);
    //mywindow = window.open("'selectExistSerial.cfm?pcp_id='+PCP+','1351625603240','width=300,height=150,resizable=1,left=650,top=300'");
    mywindow = window.open('selectExistSerial.cfm?pcp_id='+PCP,'mywindow','width=650,height=350,resizable=1,left=650,top=300,scrollbars=1');
    }
}
<form action="man_insp_enter_serial.cfm" name="frm_CreatePCP" method="post" > <!-- changed name to id name="frm_CreatePCP" -->
    <input type="hidden" name="part" value="<cfoutput>#form.part#</cfoutput>">
    <table border="1" cellpadding="6" cellspacing="2" align="center" >
        <tr>
            <td align="center"  colspan="2" bgcolor="#CCCCCC"><div class="bluem" >Start Manual Inspection Template</div></td></tr>
        <tr>
            <td align="center"  >
                <b>Part:&nbsp;&nbsp;</b>
                <select name="PCP_ID" onchange="fillSerial();" >
                    <option value="">Choose One</option>
                    <SCRIPT language=JavaScript type="text/javascript">
                        var Serial_array = new Array();
                        var PCP_array = new Array();
                    </SCRIPT>               
                    <cfset j=1>
                    <cfoutput query="qryAporvedPCP">
                        <option value="#qryAporvedPCP.PCP_ID#" <cfif qryAporvedPCP.PCP_ID eq form.part> selected </cfif> >#qryAporvedPCP.PARTNUM#</option>
                        <SCRIPT language=JavaScript type= "text/javascript" >
                            Serial_array[#j#] = "#qryAporvedPCP.MAX_SERIAL#";
                            PCP_array[#j#] = "#qryAporvedPCP.PCP_ID#";
                        </SCRIPT>
                        <cfset j=j+1>
                        <!-- <cfset ary_PCP_ID = ListToArray( valueList(qryAporvedPCP.PCP_ID) ) >
                        <cfset ary_SERIAL = ListToArray( valueList(qryAporvedPCP.MAX_SERIAL) ) > -->
                        </cfoutput>
                </select>
                </td>
                <td >Serial Number: <input type="text" name="sn" size="7" maxlength="7" style="text-transform:uppercase; text-align:center; font-weight:bold" onkeypress="return isNumberDecKey(event);" value="" />&nbsp;<input type="button" name="openSerial" value ="S/N Used"  onclick="javascript: openSerialWindow()" ></td>
            <input type="hidden" name="freq" value="0"  />
            <input type="hidden" name="temp" value="68"  />
        </tr>
    </table>
</form>

Solution

  • I test your code and it shows error in all browsers including IE. I get the same error like the one in your screenshot. The error shows the code you get the <select> value in PCP is wrong. You can edit the code into document.frm_CreatePCP.PCP_ID[pcpSelect].value. Then it can get the value correctly and works in all browsers.