Solved

How to pass a javascript variable to Cold fusion

Posted on 2010-11-16
4
342 Views
Last Modified: 2012-05-10
I am using a jquery/ajax function to check a username for availability in a database table.  It is working great... but I need to know how to validate the form that the username field resides in.  Currently, if the cfc returns true... it adds text in a div (css driven). Perfect, but if the username is not available, I do not want the user to be able to submit the form.

Obviuosly I can validate forms, but how to do it in this instance??

Any help appreciated...
check.cfm:
_________________________

<script type="text/javascript">
chkUsernameUnique = function(theUsername){
	$.getJSON("/myCFC.cfc", {
		method: 'chkUsername',
		Username: theUsername,
		returnformat: 'json'
	}, function(isUsernameUnique){
	
		if (isUsernameUnique == true) {
			$("#theErrorDivID").html('Please select a new username, that one is taken');
		}
		else {
			$("#theErrorDivID").html('Username is available');
		}
	});
};
</script>

<div id="theErrorDivID"></div>
<input type="text" name="username" id="username" onchange="chkUsernameUnique(this.value);" />


++++++++++++++++++++++++++++++++++++++++++++

.cfc
_____________________
<cfcomponent>
<cffunction name="chkUsername" access="remote" returnformat="json" output="false">
		<cfargument name="Username" required="true">
			
		<cfquery name="chkUsername" datasource="#request.dsn#" username="#request.dsnUsername#" password="#request.dsnPassword#">
		SELECT cst_ID FROM tbl_customers WHERE cst_username = <cfqueryparam value="#arguments.Username#" cfsqltype="cf_sql_varchar" />
		</cfquery>
		
		<cfreturn yesNoFormat(chkUsername.recordCount)>
	</cffunction>
</cfcomponent>

Open in new window

0
Comment
Question by:14_east
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
sam2912 earned 250 total points
ID: 34144818

if (isUsernameUnique == true) {
	$("#theErrorDivID").html('Please select a new username, that one is taken');
	$("input[type=submit]").attr("disabled", true);
}
else {
	$("#theErrorDivID").html('Username is available');
	$("input[type=submit]").attr("disabled", false);
}

Open in new window

0
 

Author Closing Comment

by:14_east
ID: 34145111
Hell yea, thanks man!!
0
 

Author Comment

by:14_east
ID: 34145291
Uh-oh... I spoke to soon.  It works fine, but I realized that my "submit" button is an image foeld.   will that make a difference?
0
 
LVL 14

Expert Comment

by:sam2912
ID: 34145336
It should not make a difference. However, if using an image, user may not know that the submit button is disabled as it looks the same, disabled or not.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question