Highlighted

javascript error message

Engaged ,
Apr 08, 2016

Copy link to clipboard

Copied

Hi. I have some javascript on my Add New Part page that has a form that says if a Part Number has a C and then a number behind it (like C1557), and the CN_Entry_Initials equal an "N", and the Validation_Qty is blank, make a Javascript error message display saying to enter a Validation Qty. I am trying to make this work on my Edit page also, but the error message does not display. I think it's because I have the input text box for the Part Number disabled. We don't want users to be able to update the part number once it's entered. If I just output the result of the Part Number, the javascript still doesn't work. How can I get the javascript to pop up an error message if the Part Number is C1557 (and the part number is just output to show the result), the CN_Entry_Initials equal an "N", and the Validation_Qty is blank? Below is the javascript I have and the form is below that. Thank you.

Andy

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function verify() {

var PartNum=document.EditItem.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.EditItem.CN_Entry_Initials.value == "N" && document.EditItem.Validation_Qty.value == "") { //this will return true if the input passes the regular expression

alert("Enter a Validation Quantity for this new Custom");

}

else

{

document.EditItem.submit();

}

 

}

//  End -->

</script>

<table width=900 cellpadding="0" cellspacing="4" border="0">

<cfform name="EditItem" method="post" action="edit_ec_number_action.cfm">

<CFOUTPUT QUERY="ShowItem" MAXROWS="1">

<tr>

<td class="edit" align="right">Change or new entry:</td>

<td>

<select name="CN_Entry_Initials">

   <option value="">Select</option>

   <cfloop query="ShowCNEntryInitials">

     <option value="#CN_Entry_Initials#"

<cfif #ShowCNEntryInitials.CN_Entry_Initials# EQ #ShowItem.CN_Entry#>selected</cfif>>#CN_Entry_Initials#

   </cfloop>

   </select>

</td>

<tr>

<td class="edit" align="right" valign="middle">Part Number:<br><h6>(Limit to 25 characters)</h6></td>

<td class="edit"><input type="hidden" name="#Part_Number#">#Part_Number#</td>

</tr>

<tr>

<td class="edit" align="right">Validation Quantity:</td>

<td>

<cfinput type="Text" name="Validation_Qty" size="12" value="#Trim(Validation_Qty)#" validate="integer">

</td>

</tr>

<tr>

<td>

<input type="button" value="Update"  onclick="verify();">

</td>

</tr>

</table>

Views

412

Likes

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

javascript error message

Engaged ,
Apr 08, 2016

Copy link to clipboard

Copied

Hi. I have some javascript on my Add New Part page that has a form that says if a Part Number has a C and then a number behind it (like C1557), and the CN_Entry_Initials equal an "N", and the Validation_Qty is blank, make a Javascript error message display saying to enter a Validation Qty. I am trying to make this work on my Edit page also, but the error message does not display. I think it's because I have the input text box for the Part Number disabled. We don't want users to be able to update the part number once it's entered. If I just output the result of the Part Number, the javascript still doesn't work. How can I get the javascript to pop up an error message if the Part Number is C1557 (and the part number is just output to show the result), the CN_Entry_Initials equal an "N", and the Validation_Qty is blank? Below is the javascript I have and the form is below that. Thank you.

Andy

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function verify() {

var PartNum=document.EditItem.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.EditItem.CN_Entry_Initials.value == "N" && document.EditItem.Validation_Qty.value == "") { //this will return true if the input passes the regular expression

alert("Enter a Validation Quantity for this new Custom");

}

else

{

document.EditItem.submit();

}

 

}

//  End -->

</script>

<table width=900 cellpadding="0" cellspacing="4" border="0">

<cfform name="EditItem" method="post" action="edit_ec_number_action.cfm">

<CFOUTPUT QUERY="ShowItem" MAXROWS="1">

<tr>

<td class="edit" align="right">Change or new entry:</td>

<td>

<select name="CN_Entry_Initials">

   <option value="">Select</option>

   <cfloop query="ShowCNEntryInitials">

     <option value="#CN_Entry_Initials#"

<cfif #ShowCNEntryInitials.CN_Entry_Initials# EQ #ShowItem.CN_Entry#>selected</cfif>>#CN_Entry_Initials#

   </cfloop>

   </select>

</td>

<tr>

<td class="edit" align="right" valign="middle">Part Number:<br><h6>(Limit to 25 characters)</h6></td>

<td class="edit"><input type="hidden" name="#Part_Number#">#Part_Number#</td>

</tr>

<tr>

<td class="edit" align="right">Validation Quantity:</td>

<td>

<cfinput type="Text" name="Validation_Qty" size="12" value="#Trim(Validation_Qty)#" validate="integer">

</td>

</tr>

<tr>

<td>

<input type="button" value="Update"  onclick="verify();">

</td>

</tr>

</table>

Views

413

Likes

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
Apr 08, 2016 0
Adobe Community Professional ,
Apr 09, 2016

Copy link to clipboard

Copied

It is difficult to offer suggestions on your code because it is incomplete. You left out the end-tags for cfform, cfoutput and option.

In any case, there are corrections you have to make:

1) Specify the regex more prcisely. For example, if the Part Number must have exactly 4 digits, then use something like ^(c|C)[0-9]{4}. If it may have 1 to 6 digits, use ^(c|C)[0-9]{1,6}.

2) I think that, in your HTML, the table belongs inside the form, not the other way round.

3) Use form instead of cfform. That would at once solve a second problem: you shouldn't mix cfinput eith input tags.

4) The following is wrong, as it misses an option end-tag, amongst others:

   <cfloop query="ShowCNEntryInitials">

     <option value="#CN_Entry_Initials#"

<cfif #ShowCNEntryInitials.CN_Entry_Initials# EQ #ShowItem.CN_Entry#>selected</cfif>>#CN_Entry_Initials#

   </cfloop>

It should be

   <cfloop query="ShowCNEntryInitials">

     <option value="#ShowCNEntryInitials.CN_Entry_Initials#"  <cfif ShowCNEntryInitials.CN_Entry_Initials EQ ShowItem.CN_Entry>selected</cfif>>#ShowCNEntryInitials.CN_Entry_Initials#</option>

   </cfloop>

5) The following is wrong, as it misses the value attribute and very likely has the wrong name:

   <input type="hidden" name="#Part_Number#">

It should be something like this

   <input type="hidden" name="Part_Number" value="#ShowItem.Part_Number#">

Likes

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
Reply
Loading...
Apr 09, 2016 0
Engaged ,
Apr 11, 2016

Copy link to clipboard

Copied

BKBK,

   Thank you. We don't have a limit of digits that can be entered after the letter C. I've updated some of the code so that the table is inside the form and I don't have any cfform's anymore. I've also updated the drop down menu to include the ending option tag. I've missed things like this before because it does not give me any errors so I think everything is OK. Not sure how it works then without an ending option tag.

Andy

Likes

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
Reply
Loading...
Apr 11, 2016 0
Adobe Community Professional ,
Apr 11, 2016

Copy link to clipboard

Copied

Do the changes solve your original problem?

I would advise you to impose a limit for the number of digits after C. The best value to use is the maximum number of characters allowed in the database column, part_number, minus 1.

Likes

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
Reply
Loading...
Apr 11, 2016 0
Engaged ,
Apr 12, 2016

Copy link to clipboard

Copied

BKBK,

    No, the changes did not solve my original problem. Why do you advise to limit a number of digits after the C? I would have to check with engineering to see how many digits can go after a C for the part number. I'm not sure if the program we use to create part numbers has a limit of digits after the C or not.

Andy

Likes

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
Reply
Loading...
Apr 12, 2016 1
BKBK LATEST
Adobe Community Professional ,
Apr 12, 2016

Copy link to clipboard

Copied

jamie61880 wrote:

    No, the changes did not solve my original problem.

You said originally you were getting a Javascript error message. Which error message? On which line?

Why do you advise to limit a number of digits after the C?

This is advisable, but optional. If you fail to set a limit, someone will be able to submit an arbitrarily large text field.

Likes

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
Reply
Loading...
Apr 12, 2016 0