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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ColdFusion Ajax Javascript question. Please help!!!

Status
Not open for further replies.

micjohnson

Programmer
Nov 9, 2000
86
US
Here is my question.

I have 3 form fields(Proj name, description and userid). Proj name and Proj description are new inputs from user. But for the thrid field "userid", I need to verify the existence against DB.

As now all 3 validations are working except the userid ajax validation when displays "The user does not exists" alert message and proceed to submit form instead of halt on the page.

What do I need to do to stop the flow if the user does not exists and make the customer to type a valid userid?

Thanks in advance.


fucntion checkForm(){
// Validate Proj name
if (document.form1.ProjtName.value.length == 0)
{
alert("Please enter a Project Name");
document.form1.ProjectName.focus();
return false;
}
// Validate Proj description
if (document.form1.ProjDescription.value.length == 0)
{
alert("Please enter a Project Description");
document.form1.ProjDescription.focus();
return false;
}
//AJAX call to validate userid
if (validateUserid() == false){
return false;
}

return true;
}



// Validate userid
validateUserid = function (userid){
if ($.trim(userid.value) != ''){
$.getJSON("../com/user.cfc", {
method: 'getUserInfoJSON',
attuid: userid.value,
returnformat: 'json'
}, function(strClient){
if (strClient == '') {
alert('The user does not exists.');
return false;;
}
});
}
};
 
Are you getting an error? This line:
Code:
 return false;;
has an extraneous semi-colon.

Without seeing your html it's hard to offer much more...

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
If you happen to be using CFFORM and CFINPUTs in your form to handle basic validation, and are calling your checkForm() JS function "onSubmit", that is possibly the problem.

I have had an issue where the CF auto-generated validation for fields using CFINPUT will ALWAYS return "true" if it passes that validation, regardless of anything returned by your own supplemental validation function.

If you are using CFFORM / CFINPUT and are calling your extra validation onSubmit, look at the rendered source code for your page. In my case, the CF validation inserted a call to my validation function at the end of the auto generated code, but threw in a "return true;" in such a way that the page always returned "true".

My fix was to trigger the validation using "onClick" or "onBlur" for individual fields, OR to not use CFFORM/CFINPUT.

A side note: mixing CF's auto validation via CFFORM/CFINPUT and supplemental validation using JS or jQuery will result in the validations to run separately. While not really a problem, it can be a little odd for the user, especially if you normally code your validation to show all form errors/issues at the same time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top