Solved

How to pass a javascript variable to Cold fusion

Posted on 2010-11-16
4
343 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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

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…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

628 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