I’m using the basic $.get() script for retrieving whether or not a record exists already in the database. The page called returns either yes or no depending if a record is found. Right now, it returns a blank value regardless.
This is the snippet of HTML with the specific input fields
<p><label for="participant_id">Please enter the Participant ID:</label>
<cfinput type="text" name="participant_id" value="#attributes.stPages.Content.ParticipantId#" required="yes" message="Enter the Participant ID" />
<cfif Len(trim(attributes.stPages.Content.ParticipantId)) eq 0>
<cfinput type="button" name="checkunique" value="Check if Unique" />
<cfinput type="hidden" name="participant_id_valid" value="false" />
</cfif></p>
This is the calling script
$("#checkunique").click(function() {
$.get('participant_id_check.cfm?participant_id=' + $('#participant_id').val(), function(data) {
result = data.replace(/^\s+|\s+$/g,"");
if (result) {
$('#unique-result').text('Your Participant ID is accepted');
} else {
$('#unique-result').text('Your Participant ID has already been used. Please enter another');
}
});
});
Here is the calling page. If I call it directly in the URL it works fine.
<!--- Check the database to ensure that the participant ID entered doesn't already exist (only for new entries). --->
<cfparam name="url.participant_id" default="" type="string" />
<cfquery name="checkID" datasource="#APPLICATION.strConfig.datasource#">
SELECT sessionid
FROM tblsessions
WHERE participant_id = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.participant_id#" null="no" />
</cfquery>
<!--- No record found; value is unique --->
<cfif Not checkID.RecordCount>
Yes
<cfelse>
No <!--- Record found; value is not unique--->
</cfif>
You are not using
$.getcorrectly, try this:Also a side point, you have nothing with the
id='participant_id'so$('#participant_id').val()probably won’t get you anything