Gray out or disable text box
Hi,
I have a drop down menu called CN_Entry_Initials that has options of a "C" or an "N". I also have a text box called Part_Number to enter a part number into. I want the Part Number text box to be grayed out or disabled until either a "C" or an "N" has been chosen out of the CN_Entry_Initials drop down menu. I have this working, except that I cannot get the Add button to do anything. I think it’s something to do with the way I have the If statement for this disabled text box, or do I have to change the button to a submit button. Does anyone know how to fix this? Below is the javascript and the drop down menu and text box code along with the Add or submit button. There is extra stuff in the Javascript that I have on the page, but I don't need to worry about those things since they are working correctly. I have the disabled text box code at the top of the javascript under the function verify() code. Thanks.
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Wayne Nolting (w.nolting@home.com) -->
<!-- This script and many more are available free online at -->
<!-- Begin
function verify()
{
if (document.getElementById('CN_Entry_Initials').value == "C"
|| document.getElementById('CN_Entry_Initials').value == "N")
document.getElementById('Part_Number').disabled = false;
else
document.getElementById('Part_Number').disabled = true;
}
{
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.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");
}
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 since Doc Changes Only is yes");
}
<!--- else if (document.AddECNumber.P_Drive_Docs_Initials.value == "i")
// self.location='eco_search.cfm'; --->
else
{
document.AddECNumber.submit();
}
}
// End -->
</script>
<cfform name="AddECNumber" action="add_new_ec_number_action.cfm" method="post">
<tr>
<td class="edit" align="right">Change or new entry:</td>
<td>
<select name="CN_Entry_Initials" id="CN_Entry_Initials" onchange="verify();">
<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" valign="middle">Part Number:<br><h6>(Limit to 25 characters)</h6></td>
<td><input type="text" name="Part_Number" id="Part_Number" maxlength="25" size="27" disabled="disabled"></td>
<td><textarea name="Description" cols="30" rows="3"></textarea></td>
</tr>
<input type="button" value="Add" onclick="verify();">
</cfform>
Thanks.
Andy
