• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Require both drop downs to be equal

Engaged ,
Nov 09, 2011 Nov 09, 2011

Copy link to clipboard

Copied

Hi. I have 2 drop downs per row of data that are for PNR and BOM initials. I want each row with both of these drop downs to match when submitted. If they don't, an error pops up saying that they have to match if there's something chosen in each drop down. I also have another column to tell if the part is a Change or New Entry by populating it with a "C" or an "N". When the part is an "N", the PNR Initials can be chosen and the BOM initials can be blank and it will go through fine. If it's an "N" and the BOM Initials are chosen and the PNR Initials are blank, an error pops up saying that the PNR Initials have to be chosen.

        When the part is a "C", there are no restrictions, other than if there are initials chosen in each drop down, they have to match. It doesn't matter if one or the other is left blank.

         I almost have all this working with Javascript, except that when just an "N" is on the page and initials are chosen for each column that don't match, the error pops up, which is good, but then when I click ok, it goes through and inserts the initials into the database. Why is that?

        I also have a problem when there are just "C" part numbers on the page, the javascript does not work at all. No errors stop the 2 drop down initials from being entered when they don't match. There has to be an "N" on the page for the code to work at all. When this javascript was first created, it was just for the "N" part numbers, but then we wanted all the rows to have the code for the initials matching each other, so I added this code to the existing code and I have these problems now. Should I have created another javascript? The only problem is the onsubmit says this: onsubmit="return verify();"  So I can't name another javascript file with the same name, can I, or can I?

       There's some code towards the bottom that says if the Change or New Entry column is an "N" or "C", to do some stuff. I have attached the whole page of code, so you can see exactly what I'm talking about. Can someone help me with this? Thanks.

Andy

<!------------------- INCLUDE HEADER  ----------------------->

<div align="center">

<table width="%*" cellpadding="0" cellspacing="0" border="0">

<center>

<cfinclude template="Includes/header.cfm">

</center>

</table>

<CFQUERY NAME="ShowInitials" Datasource="#application.DataSource#">

    SELECT *

    From Users

    where Engineer_Initials = yes and Initials <> '#cookie.UserInitials#'

    Order by Initials

</CFQUERY>

<CFQUERY NAME="PNRBOMSearch" Datasource="#application.DataSource#">

    SELECT ECID, Requested_By_Initials, EC_Completion_Initials, EC_Completion_Date, Flag_Comments, Comments, ItemID, ECID_SPEC, ECO_Start_Date, Date_Requested, Part_Number, Description, P_Drive_Docs, Release_Status, Validation_ItemID, Validation_ECID, Validation_Qty, Open_Jobs_Affected, CN_Entry, SW_Model_Only,

    Approval_PNR.APVID as PNR_APVID,

    Approval_BOM.APVID as BOM_APVID,

       

    Approval_PNR.Approval_Initials as PNR_Initials,

    Approval_BOM.Approval_Initials as BOM_Initials,

    Approval_PNR.Doc_Rev as PNR_Rev,

    Approval_BOM.Doc_Rev as BOM_Rev

   

    FROM ((((ECO_Master LEFT JOIN ECO_Items ON ECO_Master.ECID = ECO_Items.ECID_SPEC)

    LEFT JOIN Validation_Records ON ECO_Items.ItemID = Validation_Records.Validation_ItemID)

    LEFT JOIN Approval as Approval_PNR ON (ECO_Items.ItemID = Approval_PNR.APV_ItemID AND Approval_PNR.Document_Type = 'PNR Req'))

    LEFT JOIN Approval as Approval_BOM ON (ECO_Items.ItemID = Approval_BOM.APV_ItemID AND Approval_BOM.Document_Type = 'BOM Req'))

   

    WHERE Requested_By_Initials = '#cookie.UserInitials#'

    AND EC_Completion_Date Is Null

    <!--- And PNR_BOM_Entry_Date Is Null --->

    And SW_Model_Only = 0

    And Doc_Changes_Only = 0

   

<!--- Want all the PNR Rev ones that are Null or = '' to show up and if the BOM Rev ones are not empty since user was assigned and user would not have filled in the PNR Rev yet. This is just one example. --->

And ((Approval_PNR.Approval_Initials Is Not Null And Approval_PNR.Approval_Initials <> '' And (Approval_PNR.Doc_Rev Is Null Or Approval_PNR.Doc_Rev = '') And Approval_BOM.Approval_Initials Is Not Null And Approval_BOM.Approval_Initials <> '' And Approval_BOM.Doc_Rev Is Not Null And Approval_BOM.Doc_Rev <> '')

Or (Approval_PNR.Approval_Initials Is Not Null And Approval_PNR.Approval_Initials <> '' And (Approval_PNR.Doc_Rev Is Null Or Approval_PNR.Doc_Rev = ''))

Or (Approval_BOM.Approval_Initials Is Not Null And Approval_BOM.Approval_Initials <> '' And (Approval_BOM.Doc_Rev Is Null Or Approval_BOM.Doc_Rev = '') And Approval_PNR.Approval_Initials Is Not Null And Approval_PNR.Approval_Initials <> '' And Approval_PNR.Doc_Rev Is Not Null And Approval_PNR.Doc_Rev <> '')

Or (Approval_BOM.Approval_Initials Is Not Null And Approval_BOM.Approval_Initials <> '' And (Approval_BOM.Doc_Rev Is Null Or Approval_BOM.Doc_Rev = ''))

Or ((Approval_PNR.Approval_Initials Is Null or Approval_PNR.Approval_Initials = '') And Approval_PNR.Doc_Rev Is Null And (Approval_BOM.Approval_Initials Is Null or Approval_BOM.Approval_Initials = '') And Approval_BOM.Doc_Rev Is Null))

   

    ORDER BY ECID ASC, ItemID ASC

</CFQUERY>

<CFOUTPUT>

<!----------------------- SEARCH PROMPT ----------------------->

<head>

    <title>Select Engineer for PNR/BOM Approvals</title>

    <link href="styles/admin.css" rel="stylesheet" type="text/css">

   

    <!--- Can tell that "N" is selected in theCN_Entry column because of If statement on line 234 below. --->

    <SCRIPT LANGUAGE="JavaScript">

        function verify() {

            var partNumber = '';

            var ecoNumber = '';

            var bom;

            var bomValue='';

            var pnr;

            var pnrValue='';

            var requiredArray = document.getElementById('PNR_Required_ID_List').value.split(",");

            var allArray = document.getElementById('listofids').value.split(",");

            var sameArray = document.getElementById('Same_Required_ID_List').value.split(",");

            var allArrayInit = document.getElementById('listofids').value.split(",");

            var error=false;

           

            for(var i=0;i<requiredArray.length;i++) {

                pnr = document.getElementById('PNR_Approval_Initials'+requiredArray);

                bom = document.getElementById('BOM_Approval_Initials'+requiredArray);

                pnrValue = pnr[pnr.selectedIndex].value;

                bomValue = bom[bom.selectedIndex].value;

               

                if(bomValue != '' && pnrValue == '') {

                    error=true;

                    ecoNumber = document.getElementById('ECID'+requiredArray).value;

                    partNumber = document.getElementById('Part_Number'+requiredArray).value;

                    alert("You must enter some PNR initials for ECO " + ecoNumber + " Part Number: " + partNumber);

                }

               

                if(bomValue != pnrValue && bomValue != '') {

                    error=true;

                    ecoNumber = document.getElementById('ECID'+requiredArray).value;

                    partNumber = document.getElementById('Part_Number'+requiredArray).value;

                    alert("PNR and BOM Initials must be the same for ECO " + ecoNumber + " Part Number: " + partNumber);

                }

               

               

            }

           

            for(var i=0;i<allArray.length;i++) {

                pnr = document.getElementById('PNR_Approval_Initials'+allArray);

                bom = document.getElementById('BOM_Approval_Initials'+allArray);

               

                pnrValue = pnr[pnr.selectedIndex].value;

                bomValue = bom[bom.selectedIndex].value;

               

               

            }

           

           

           

            for(var i=0;i<sameArray.length;i++) {

                pnr = document.getElementById('PNR_Approval_Initials'+sameArray);

                bom = document.getElementById('BOM_Approval_Initials'+sameArray);

                pnrValue = pnr[pnr.selectedIndex].value;

                bomValue = bom[bom.selectedIndex].value;

               

                if(bomValue != pnrValue && pnrValue != '' && bomValue != '') {

                    error=true;

                    ecoNumber = document.getElementById('ECID'+sameArray).value;

                    partNumber = document.getElementById('Part_Number'+sameArray).value;

                    alert("PNR and BOM Initials must be the same for ECO " + ecoNumber + " Part Number: " + partNumber);

                }

            }

           

            for(var i=0;i<allArrayInit.length;i++) {

                pnr = document.getElementById('PNR_Approval_Initials'+allArrayInit);

                bom = document.getElementById('BOM_Approval_Initials'+allArrayInit);

               

                pnrValue = pnr[pnr.selectedIndex].value;

                bomValue = bom[bom.selectedIndex].value;

               

               

            }

           

           

            if(error) {

            return false;

        }

        else {

            return true;

            }

        }

    </script>

   

    <!---         This works above in the brackets, but not here on it's own after the Change Value code.

    if(bomValue !== pnrValue) {

                    error=true;

                    ecoNumber = document.getElementById('ECID'+requiredArray).value;

                    partNumber = document.getElementById('Part_Number'+requiredArray).value;

                    alert("PNR and BOM Initials must be the same for ECO " + ecoNumber + " Part Number: " + partNumber);

                } --->

               

               

       

</head>

<body>

<div align="center">

          

<table width=800 cellspacing="0" cellpadding="0" align="center" border="0">

    <tr>

        <td align="left" class="foundprompt">

        <center>

            <img src="images/found.gif" width="22" height="22" border="0" alt="">

            #cookie.UserInitials#- Select Engineer for PNR/BOM Approvals

        </center>

        </td>

    </tr>

    <tr><td> </td></tr>

</table>

<!--- Output Records Table --->

<table width=*% align="center" cellspacing="4" cellpadding="0" border="0">

<tr>

    <!--- <td><B>ItemID</B></td> --->

    <td><B>Flag</B>   </td>

    <td><B>ECO</B>   </td>

    <!--- <td><B>APVID - PNR</B>   </td>

    <td><B>APVID - BOM</B>   </td> --->

    <td><B>Part Number   </B></td>

    <td align="center"><B>Change or<br>new entry</B></td>

   

    <td align="center" width="2" bgcolor= "gray"><BR></td>

   

    <td align="center"><B>PNR<br>Initials</B></td>

    <td align="center" width="50"><B>PNR<br>Rev</B></td>

   

    <td align="center" width="2" bgcolor= "gray"><BR></td>

   

    <td align="center"><B>BOM<br>Initials</B></td>

    <td align="center" width="50"><B>BOM<br>Rev</B></td>

   

    <td align="center" width="2" bgcolor= "gray"><BR></td>

   

    <td align="center"><B>Open Jobs Affected</B></td>

   

    <td align="center" width="2" bgcolor= "gray"><BR></td>

   

    <td align="center"><B>Comments</B></td>

</tr>

<tr>

<td colspan="15"><hr>

</td>

</tr>

<!---------------- OUTPUT Company SEARCH RESULTS ---------------->

<cfform name="EditItem" method="post" action="Queue_PNR_BOM_action.cfm" onsubmit="return verify();">

<!--- The Set PreviousECID code below before and after the cfloop puts a line in between the ECO's so they are in sections and all the items for 1 ECO are together. --->

<cfset PreviousECID = PNRBOMSearch.ECID>

<cfset PNR_Required_ID_List = "" />

<cfset Same_Required_ID_List = "" />

<cfloop query="PNRBOMSearch">

    <cfif PreviousECID NEQ PNRBOMSearch.ECID>

        <tr><td colspan="15"><hr>

        </td></tr>

    </cfif>

   

    <cfset PreviousECID = PNRBOMSearch.ECID>

    <input type="hidden" name="ItemID#ItemID#" value="#ItemID#">

    <input type="hidden" name="ECID#ItemID#" id="ECID#ItemID#" value="#ECID#">

    <input type="hidden" name="PNR_Document_Type#ItemID#" value="PNR Req">

    <input type="hidden" name="BOM_Document_Type#ItemID#" value="BOM Req">

    <input type="hidden" name="Part_Number#ItemID#" id="Part_Number#ItemID#" value="#Part_Number#">

    <input type="hidden" name="CN_Entry#ItemID#" id="CN_Entry#ItemID#" value="#CN_Entry#">

<input type="hidden" name="PNR_Rev#ItemID#" value="#PNR_Rev#">

<input type="hidden" name="BOM_Rev#ItemID#" value="#BOM_Rev#">

<input type="hidden" name="Flag_Comments#ItemID#" value="'X'">

    <tr>

   

<td>

<cfif Comments Is Not "">

  <font size = "5" color=dd0000><strong>#Flag_Comments#</strong></font>

<cfelse>

 

</cfif>

</td>

       

        <td align="center">

        <cfif ECID is not "">

            #ECID#

            <!--- <a href="item_display.cfm?ECID=#ECID#">#ECID#</a> --->

        <cfelse>

             

        </cfif>

        </td>

       

       

        <td width="auto">

        <cfif Part_Number Is Not "">

            #Part_Number#

        <cfelse>

             

        </cfif>

        </td>

       

        <td align="center">

        <cfif CN_Entry Is Not "">

            #CN_Entry#

        <cfelse>

             

        </cfif>

        </td>

       

<td align="center" width="2" bgcolor= "gray"><BR></td>

        <cfset PNRInitials = PNRBOMSearch.PNR_Initials>

        <td align="center"> 

            <select name="PNR_Approval_Initials#ItemID#" id="PNR_Approval_Initials#ItemID#">

                <option value="">PNR Initials</option>

               

                <cfloop query="ShowInitials">

                <!--- This If statement says to not display the Login person's initials in the drop down menu. Might not really need this If Statement since it's a filter on the ShowInitials query above. --->

                <cfif '#cookie.UserInitials#' NEQ PNRInitials>

                    <option value="#Initials#" <cfif Initials EQ PNRInitials>selected</cfif>>#Initials#</option>

                </cfif>

               

                </cfloop>

            </select>

        </td>

<td align="center">

<cfif PNR_Rev Is Not "">

#PNR_Rev#

<cfelse>

 

</cfif>

</td>

<td align="center" width="2" bgcolor= "gray"><BR></td>

        <cfset BOMInitials = PNRBOMSearch.BOM_Initials>

        <td align="center"> 

            <select name="BOM_Approval_Initials#ItemID#" id="BOM_Approval_Initials#ItemID#">

                <option value="">BOM Initials</option>

               

                <cfloop query="ShowInitials">

               

                <cfif '#cookie.UserInitials#' NEQ PNRInitials>

                    <option value="#Initials#" <cfif Initials EQ BOMInitials>selected</cfif>>#Initials#</option>

                </cfif>

               

                </cfloop>

            </select>

        </td>

       

<td align="center">

<cfif BOM_Rev Is Not "">

#BOM_Rev#

<cfelse>

 

</cfif>

</td>

<td align="center" width="2" bgcolor= "gray"><BR></td>

        <td> 

        <cfif CN_Entry EQ "C">

            <input name="Open_Jobs_Affected#ItemID#" type="text" value="#Trim(Open_Jobs_Affected)#" size="30">

<cfelse>

 

</cfif>

        </td>

       

<td align="center" width="2" bgcolor= "gray"><BR></td>

<td>

<textarea name="Comments#ItemID#" cols="38" rows="2">#Trim(Comments)#</textarea>

</td>   

   

    </tr>

   

    <cfif CN_Entry EQ "C">

        <cfset Same_Required_ID_List = ListAppend(Same_Required_ID_List, ItemID) />

    </cfif>

   

    <cfif CN_Entry EQ "N">

        <cfset PNR_Required_ID_List = ListAppend(PNR_Required_ID_List, ItemID) />

    </cfif>

</cfloop>

<tr><td> </td></tr>

<tr>

    <td colspan="14" align="center">

    <input type="Hidden" name="Same_Required_ID_List" id="Same_Required_ID_List" value="#Same_Required_ID_List#">

   

    <input type="Hidden" name="PNR_Required_ID_List" id="PNR_Required_ID_List" value="#PNR_Required_ID_List#">

    <input type="submit" value="Update"> 

    <!--- <input type="submit" value="Update">  --->

    <input type="reset" value="Reset">

    </td>

</tr>

</table>

<input type="hidden" name="listofids" id="listofids" value="#ValueList(PNRBOMSearch.ItemID)#">

</cfform>

<!--------------------- INCLUDE FOOTER ------------------------>

<cfinclude template="Includes/footer.cfm">

</table>

</div>

</body>

</html>

</cfoutput>

Views

503

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 10, 2011 Nov 10, 2011

Copy link to clipboard

Copied

LATEST

Hi Andy,

that is a LOT of code to ask someone to sift through.  I'm not sure you're going to get a lot of folks who will have the time to go through the entire code line by line to find your glitch.  In general, whenever a problem like this pops up, its a good idea to reduce the code down to a gist proof-of-concept to see if you can get your functionality working in a vacuum (so to speak) in order to make sure it works.

Based on your description (i.e. the error pops up, but it still lets you submit the form) it sounds like your validation is on the selection, but you don't have any validation on the submission of the form (e.g. the form's onSubmit() handler).  Without that, there is nothing that tells the form NOT to submit - it is largely ignorant of any javascript alerts you might have thrown up associated with other page elements.

Hope that helps!

- Michael

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation