Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Utilizing Java "check(string.length)" function in ColdFusion

Status
Not open for further replies.

VinceMan

Technical User
Dec 4, 2006
1
US
Hi everyone I am trying to utilize javascript to check the length of one of my coldfusion inputs. Here is the code I have come up with to verify and chedk the string. I have very little java knowledge so I'm not sure if this is correct.

<script language="JavaScript">
function CheckMgrID(string) {
var error = "";
if (!(string.length == 6))
{
error = "ManagerID must be characters long.";

}
return error;
}
function CheckForm(insertEmpITDataDetailsAdd) {
var why ="";
why += CheckMgrID(insertEmpITDataDetailsAdd.'ItemID#getIDDetails.ItemID#_DetailID#getIDDetails.ID#'.value);
if (why != "") {
why="Please fill in the following mandatory fields:\n\n\n"+why;
alert(why);
return false;
}
return true
}
</script>

name of the form: insertEmpITDataDetailsAdd
name of the input that is being checked:
'ItemID#getIDDetails.ItemID#_DetailID#getIDDetails.ID#'

I understand if no one can help me out in coldfusion but if someone could at least verify my javascript code and make sure it is okay I would be very grateful. For my form I have the following code:

<cfform name="insertEmpITDataDetailsAdd" action="template.cfm" method="post" onsubmit ="return checkMgrID(this)">
 
Man.... that code is a mess....

First, you really should indent your code. If you are new to javascript, or new to programming in general - proper indentation will make your code 10000% easier to debug (and that is not an over-exaggeration).

Second, if (!(string.length == 6)) really should be rewritten as if (string.length != 6) - it's much cleaner even though they mean the same thing.

Third, javascript is case sensitive, so things like this will fail since your function is defined with an uppercase C:
Code:
<cfform name="insertEmpITDataDetailsAdd" action="template.cfm" method="post" onsubmit ="return [!]c[/!]heckMgrID(this)">
Fourth, your form onsubmit function really seems like it should be calling the CheckForm function instead of the CheckMgrID function:
Code:
<cfform name="insertEmpITDataDetailsAdd" action="template.cfm" method="post" onsubmit ="return Check[!]Form[/!](this)">

I'm not sure about the cold fusion part where you are referencing the element as 'ItemID#getIDDetails.ItemID#_DetailID#getIDDetails.ID#' - I'm guessing that's cold fusion syntax to essentially "response.write" out the name of the field to the client. So, if that part is causing you problems I'm not sure I can help since this is a javascript forum, and I don't know cold fusion.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top