Is there a way to perform a cfquery within Javascript

I have a form that when you submit the "add" it executes javascript to validate the entered data.  I would like to validate that the record that the user is trying to add does not already exist in the database (Oracle).  Is there a way to stay on the same form and display an alert if there is match found on the database?
lindadudleyAsked:
Who is Participating?
 
cheekycjCommented:
do you mean without submitting.. well one option is to query your oracle DB to create a JS array of the primary key.

Then validate against that array before the user submits.. but remember.. if a user has JS disabled.. you are out of luck.

CJ
0
 
Scott BennettManager TechnologyCommented:
Another point to be aware of is that if you create a JS array of the user names then if the user views the source code and know anything about javascript, they will be able to see a list of every user name in your system.

I would suggest submitting the form and doing a server-side validation.

-Scott

0
 
Scott BennettManager TechnologyCommented:
Also, FYI - There is no way for you to do a query against your Oracle database on the client-side. All your queries must be done on the server side.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
cheekycjCommented:
Server side validation is the safest way.

CJ
0
 
dash420Commented:
In my point view it is always to check this after in separate page i.e. which page ur going to insert into database.
:-)
0
 
MikeForbesCommented:
I agree whole-heartedly.  I usually will add code to the page that will be doing my insert/update, something like:

<cfquery datasource=#dsname# name="Test">
Select name_id, name
from table
where name_id = #form.name_id#
</cfquery>

<CFIF #Test.RecordCount# GT 0>
Hey, you already exist!
<input type="button" value="Back" onclick="history.back(-1);">
<cfabort>
</cfif>

Mike
0
 
YogCommented:
Is it browser specific.

If not, try using the Microsoft.XMLHTTP component. Pretty cool but will work in IE5.0 and above only..

cheers.
0
 
CFDevHeadCommented:
lindadudley,
No comment has been added lately (972 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: split points between cheekycj, SBennett,  dash420 and MikeForbes

Please leave any comments here within 4 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

CFDevHead
EE Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.