Copy link to clipboard
Copied
Can someone help me with some javascript I'm having a hard time with? Below is the section I'm having a problem with. The PNR_BOM_Change_Only is a yes/no drop down, but the values are 0 and 1. The CN_Entry_Initials and Release_Status_Initials are drop downs that have a few options in them to choose from. The CN_Entry_Initials has a Null Value, C, or an N option. The Release_Status_Initials has only a U and N option. I'm trying to get this javascript to display an alert box if the PNR_BOM_Change_Only is a 1 and the CN_Entry_Initials is not equal to a C, and the Release_Status_Initials is not equal to an N. This alert box works if the PNR_BOM_Change_Only is a 1 and if I choose an N in the CN_Entry_Initials drop down and the Release_Status_Initials is a U, but it does not work if I choose an N in the CN_Entry_Initials drop down and the Release_Status_Initials is an N. This ends up processing through and it shouldn't yet because the CN_Entry_Initials is not a C. If I remove either the CN_Entry_Initials or the Release_Status_Initials code and keep the PNR_BOM_Change_Only code, this does work just fine then. What am I doing wrong?
else if(document.AddECNumber.PNR_BOM_Change_Only.value == "1" && document.AddECNumber.CN_Entry_Initials.value != "C" && document.AddECNumber.Release_Status_Initials.value != "N") { //this will return true if the input passes the regular expression
alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM Change Only is yes");
}
Andy
Using the quotes did not work. This is what I got working with what I needed it to do:
else if(document.AddECNumber.PNR_BOM_Change_Only.value == "1" && document.AddECNumber.CN_Entry_Initials.value != "C" && (document.AddECNumber.Release_Status_Initials.value == "U"
|| document.AddECNumber.Release_Status_Initials.value == "N")) { //this will return true if the input passes the regular expression
alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM C
...Copy link to clipboard
Copied
Hi,
Pls try this.
else if(document.getElementById(PNR_BOM_Change_Only).value == "1" && document.getElementById(CN_Entry_Initials).value != "C" && document.getElementById(Release_Status_Initials).value != "N") { //this will return true if the input passes the regular expression
alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM Change Only is yes");
}
Note: In your file, you should be having ids as the same name like id = "PNR_BOM_Change_Only" etc.
Copy link to clipboard
Copied
Meensi,
I tried your code above and made the id's for each of the drop downs as above, but it did not work. It would not go through at all, but then I changed the update button to be a submit button rather than just a regular button. It went through, but never gave me any alert box when I didn't do it right. Any other ideas? Thanks.
Andy
Copy link to clipboard
Copied
OK, Try to break your elseif() condition and test for each condition.
Alert the values of the dropdown, sometimes, it might be coming a True instead of 1. so check for that.
After your submiiting a button, a form will be submitted or you will be calling a function, in that function, try to give alert for testing purpose and check for each line.
If possible can you post your html code also??
Copy link to clipboard
Copied
Meensi,
I can get the if statement to work if I use just this:
else if(document.AddECNumber.PNR_BOM_Change_Only.value == "1" && document.AddECNumber.CN_Entry_Initials.value != "C") {
alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM Change Only is yes");
}
or if I use this:
else if(document.AddECNumber.PNR_BOM_Change_Only.value == "1" document.AddECNumber.Release_Status_Initials.value != "N") {
alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM Change Only is yes");
}
Here's my entire page's code with what you told me to change:
<html>
<!--- <cfset MyHost = CGI.Server_Name>
<CFIF CGI.HTTP_Referer does not contain "#MyHost#">
<cflocation url="../Login/login.cfm" addtoken="No">
</CFIF> --->
<head>
<!--- Script that tests if Cnumber exists in the Part Number field and Validation_Qty is blank, then require the validation qty to be filled in, otherwise, just let it be entered the way it is. This does not test for a blank after the C however. --->
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Wayne Nolting (w.nolting@home.com) -->
<!-- This script and many more are available free online at -->
<!-- Begin
function verify() {
var PartNum=document.AddECNumber.Part_Number.value;
var regularExpression = new RegExp(/[cC][0-9]/); //regular expression to check for a letter C followed by a number
if(regularExpression.test(PartNum)&& document.AddECNumber.CN_Entry_Initials.value == "N" && document.AddECNumber.Validation_Qty.value == "") { //this will return true if the input passes the regular expression
alert("Enter a Validation Quantity for this new Custom");
}
else if(document.AddECNumber.CN_Entry_Initials.value == "N" && document.AddECNumber.P_Drive_Docs_Initials.value == "i") { //this will return true if the input passes the regular expression
alert("You cannot select 'i' for docs to be removed for a new part");
}
else if(document.AddECNumber.CN_Entry_Initials.value == "" && document.AddECNumber.SW_Model_Only.value == "0") { //this will return true if the input passes the regular expression
alert("ECO type required - Select (N)ew or (C)hange for eco line item");
}
else if(document.getElementById(PNR_BOM_Change_Only).value == "1" && document.getElementById(CN_Entry_Initials).value != "C" && document.getElementById(Release_Status_Initials).value != "N") { //this will return true if the input passes the regular expression
alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM Change Only is yes");
}
else if(document.AddECNumber.Doc_Changes_Only.value == "1" && document.AddECNumber.CN_Entry_Initials.value != "C") { //this will return true if the input passes the regular expression
alert("ECO type required - Select (C)hange for eco line item");
}
<!--- else if (document.AddECNumber.P_Drive_Docs_Initials.value == "i")
// self.location='eco_search.cfm'; --->
if(error) {
return false;
}
else {
return true;
}
}
// End -->
</script>
<CFQUERY NAME="ShowInitials" Datasource="#application.DataSource#">
SELECT *
From Users
Order by Initials
</CFQUERY>
<CFQUERY NAME="ShowCNEntryInitials" Datasource="#application.DataSource#">
SELECT *
From CN_Entry_Initials
Order by CN_Entry_Initials
</CFQUERY>
<CFQUERY NAME="ShowPDriveDocsInitials" Datasource="#application.DataSource#">
SELECT *
From P_Drive_Docs_Initials
Order by P_Drive_Docs_Initials
</CFQUERY>
<!--- <CFQUERY NAME="ExpectedValue" DATASOURCE="#application.DataSource#">
SELECT Company, Company_Name, First_Name, Middle, Last_Name, ContactID, Contact_Num, RFQID, RFQID_SPEC, ItemID, RFQ_Expected_Value
FROM
(((Contacts LEFT JOIN RFQ_Numbers ON Contacts.ContactID = RFQ_Numbers.Contact_Num)
LEFT JOIN Companies ON Contacts.Company = Companies.Company_Name)
LEFT JOIN RFQ_SPEC ON RFQ_SPEC.ItemID = RFQ_Numbers.Item_Num)
</CFQUERY> --->
<title>Add New ECO Number</title>
<link rel="stylesheet" type="text/css" href="styles/admin.css">
</head>
<body>
<!------------------- INCLUDE HEADER ----------------------->
<div align="center">
<table width="%*" cellpadding="0" cellspacing="0" border="0">
<center>
<cfinclude template="Includes/header.cfm">
</center>
</table>
<div align="center">
<table width=*% cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="2"> </td>
</tr>
<!---------------------- LINKS ROW ------------------------->
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td> </td>
<td colspan="2"><h2 class="add">Add New ECO Number</h2>
<!----- IF USER IS REDIRECTED TO FORM PAGE AFTER SUBMISSION,
ONE OR MORE FORM FIELDS WERE INVALID. SHOW MESSAGES. ----->
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<!--------------------- ADD RECORD FORM -------------------->
<cfform name="AddECNumber" action="add_new_ec_number_action.cfm" method="post">
<CFIF IsDefined("cookie.UserInitials")>
<cfoutput>
<input type="Hidden" name="Requested_By_Initials" value="#cookie.UserInitials#">
</cfoutput>
</cfif>
<table width=700 cellpadding="0" cellspacing="4" border="0">
<cfoutput>
<tr>
<td class="edit" align="right">Requested By:</td>
<td class="edit">#cookie.UserInitials#</td>
</tr>
</cfoutput>
<tr>
<td class="edit" align="right">Date Requested:</td>
<td> </td>
<td class="edit">Description:</td>
</tr>
<!--- <tr>
<td class="edit" align="right" valign="top">Part Number:<br><h6>(Limit to 25 characters)</h6></td>
<td><input type="text" name="Part_Number" maxlength="25" size="27"></td>
</tr>
<tr>
<td class="edit" align="right" valign="middle">Description:</td>
<td><textarea name="Description" cols="30" rows="3"></textarea></td>
</tr> --->
<tr>
<td class="edit" align="right" valign="middle">Part Number:<br><h6>(Limit to 25 characters)</h6></td>
<td><input type="text" name="Part_Number" maxlength="25" size="27"></td>
<td><textarea name="Description" cols="30" rows="3"></textarea></td>
</tr>
<tr>
<td class="edit" align="right">SW Model Creation only:</d>
<td colspan="2">
<select name="SW_Model_Only">
<option value="0">No</option>
<option value="1">Yes</option>
</select>
<B><font color=dd0000>
If "yes", go directly to "Add" button below.</font></B>
</td>
</tr>
<tr>
<td class="edit" align="right">PNR/BOM Change only:</d>
<td colspan="2">
<select name="PNR_BOM_Change_Only" id="PNR_BOM_Change_Only">
<option value="0">No</option>
<option value="1">Yes</option>
</select>
</td>
</tr>
<tr>
<td class="edit" align="right">Doc Changes Only<br>(no PNR or BOM):</d>
<td colspan="2">
<select name="Doc_Changes_Only">
<option value="0">No</option>
<option value="1">Yes</option>
</select>
</td>
</tr>
<tr>
<td class="edit" align="right">Validation Quantity:</td>
<td><input type="text" name="Validation_Qty" size="12" validate="integer" <!--- required="no" ---> message="You must enter a valid number in the Validation Quantity field"></td>
</tr>
<tr>
<td class="edit" align="right">Change or new entry:</td>
<td>
<select name="CN_Entry_Initials" id="CN_Entry_Initials">
<option value="">Select</option>
<!--------- POPULATE SELECT BOX WITH P_Drive_Docs_Initials FIELDS --------->
<CFOUTPUT QUERY="ShowCNEntryInitials">
<option value="#CN_Entry_Initials#">#CN_Entry_Initials#
</CFOUTPUT>
</select>
</td>
</tr>
<tr>
<td class="edit" align="right">Docs to be Removed from P Drive:</td>
<td>
<select name="P_Drive_Docs_Initials">
<option value="">Select</option>
<!--------- POPULATE SELECT BOX WITH P_Drive_Docs_Initials FIELDS --------->
<CFOUTPUT QUERY="ShowPDriveDocsInitials">
<option value="#P_Drive_Docs_Initials#">#P_Drive_Docs_Initials#
</CFOUTPUT>
</select>
</td>
</tr>
<tr>
<td class="edit" align="right">Release Status:</td>
<td>
<select name="Release_Status_Initials" id="Release_Status_Initials">
<option selected value="U">U</option>
<option value="N">N</option>
</select>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td colspan="4"><B><font color=dd0000>
Please click add button only ONCE! Clicking it twice may cause duplicate information</font></B>
</td>
</tr>
<tr>
<td colspan="4"><B><font color=dd0000>
to be submitted. Do not use the back button once this page has been submitted.</font></B>
</td>
</tr>
<tr>
<td colspan="4"><B><font color=dd0000>
Use the editing links on the next page to edit this information.</font></B>
</td>
</tr>
<!------------------ SUBMIT/RESET FORM ------------------>
<tr>
<td> </td>
<td>
<tr>
<td> </td>
<td>
<!------------------ SUBMIT/RESET FORM ------------------>
<input type="submit" value="Add">
<input type="reset" value="Reset">
</td>
</tr>
</table>
</cfform>
<!--- Footer --->
<cfinclude template="Includes/footer.cfm">
</table>
<br>
</div>
</body>
</html>
Copy link to clipboard
Copied
meensi wrote:
Hi,
Pls try this.
else if(document.getElementById(PNR_BOM_Change_Only).value == "1" && document.getElementById(CN_Entry_Initials).value != "C" && document.getElementById(Release_Status_Initials).value != "N") { //this will return true if the input passes the regular expression
alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM Change Only is yes");
}
Note: In your file, you should be having ids as the same name like id = "PNR_BOM_Change_Only" etc.
Use quotes for the IDs, like this
document.getElementById("PNR_BOM_Change_Only").value == "1" && document.getElementById("CN_Entry_Initials").value != "C" && document.getElementById("Release_Status_Initials").value != "N"
Copy link to clipboard
Copied
Using the quotes did not work. This is what I got working with what I needed it to do:
else if(document.AddECNumber.PNR_BOM_Change_Only.value == "1" && document.AddECNumber.CN_Entry_Initials.value != "C" && (document.AddECNumber.Release_Status_Initials.value == "U"
|| document.AddECNumber.Release_Status_Initials.value == "N")) { //this will return true if the input passes the regular expression
alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM Change Only is yes");
}
else if(document.AddECNumber.PNR_BOM_Change_Only.value == "1" && document.AddECNumber.CN_Entry_Initials.value == "C" && document.AddECNumber.Release_Status_Initials.value == "U") { //this will return true if the input passes the regular expression
alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM Change Only is yes");
}
Thanks.
Andy