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

Javascript Ajax 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 coldfusion 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;;
}
});
}
};
 
How are you calling the checkFrom function?

Usually to stop a submission you must call the function from either the submit button's onclick event, or the form's onsubmit event and return a false value to either event. Returning a false value there stops the event from continuing.



Code:
<form action=...  onsubmit="[red]return[/red] checkForm();">

or even

<input type="submit" ... onclick="[red]return[/red] checkForm();">


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top