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

Execute CFQuery onBlur.....

Status
Not open for further replies.

hacole

Programmer
Jan 19, 2001
16
US
Is it possible to execute a CFQuery onBlur of a form field?? I don't want to read the whole table, and I'd like to do a query using the value entered, to validate if it exists.

Thanks,
hacole
 
You have to use a little trickery to make this work but I think it can be done. Here's what I suggest:

1. Trigger a function with onblur.
2. In this function, create a new image and set it's source attribute to be a CF script.
3. Inside the CF script, do your query and then use the <cfcontent> tag to return an image.
4. Based on the output of your query, return one of two different images that have a different size. One image indicates valid, the othe indicates in-valid.
5. Inside the js function, check the image.complete value to determine when it's fully loaded.
6. Determine which image was sent back by examining the image.height value.
7. I would use a 1x1 gif and a 1x2 gif so they'll load really fast. If the height is 1, the query indicates it's valid, if it's 2, the value is in-valid.

I've never tried this so let me know how it turns out.
GJ
 
I'm following the logic of what you're suggesting, but I have a couple questions before I jump into this:

If I understand, you're suggesting calling a JS function, which calls a CFScript?

Why does this have to be an image instead of just a variable?

Is the page going to completely reload? If so, I have to keep track of other values already entered in the form before it's submitted.

Thanks,
hacole
 
Since you're relying on the JS onblur function, I assume it's safe to implement a partial JS solution. Since you want to execute a query, you're going to have to run a CF script on the server.

The easiest way I know to do this from the clientside WITHOUT causing a page refresh is to create a new image and set it's source to a CF script ( This causes JS to request the CF script because it thinks it's requesting an image. This is why you use <cfcontent> to return an image as JS will retrieve the image even though it never displays it.

This is the same concept as hover over effects where JS downloads an image to display when you put your mouse over a button. Once the client side JS requests the script file (thinking it's retrieving an image), it will download a valid gif file which you can check the dimensions of to determine the results of the query.

There is one problem with this approach which I'll wait to mention until you have this part working as it would only confuse the issue.

Let me know how it goes,
GJ
 
I am stumped.....
I have to admit, I'm pretty new at all this. This is what I have so far, but it's not liking my code AT ALL. I would really appreciate a debugger right about now.

Anyway, I'm going to keep playing with this, but just in case I'm WAY off, I thought you would be able to tell me. I really want to figure this out, but if you see I'm going in the wrong direction - I can rethink this!!!

It keeps telling me I have a syntax error on my &quot;document.acct_info.A_ACCT_GROUP.focus();&quot; line. Also, when I try using it, it says object expected.

Here's some code:
(testIt.cfm)
<CFOUTPUT>
<SCRIPT language=&quot;JavaScript&quot;>
function valAcctGrp(AG)
{
var AcctGroup = AG.value.toUpperCase();
<IMG SRC=&quot;
if (image.complete == true)
{
if (image.height == &quot;2&quot;)
{
alert('Invalid Account Group.');
document.acct_info.A_ACCT_GROUP.focus();
}
else
{
document.acct_info.a_quick_addr.focus();
}
}
}
</SCRIPT>
</CFOUTPUT>
...
<form name=&quot;acct_info&quot; action=&quot;&quot;>
<table>
<tr><td>Account Group:  </td>
<td><CFOUTPUT><input type=&quot;Text&quot; name=&quot;A_ACCT_GROUP&quot; value=&quot;&quot; onchange=&quot;valAcctGrp(this.value)&quot;></CFOUTPUT></td>
</tr>
</table>
</form>

(checkIt.cfm)
<CFIF isdefined(&quot;AcctGroup&quot;)>
<CFSET ACCT_GROUP = #AcctGroup#>
<CFELSE>
<CFSET ACCT_GROUP = &quot;&quot;>
</CFIF>
<CFSCRIPT>

<CFQUERY NAME=&quot;GetAcctGroup&quot; DATASOURCE=&quot;#session.ORA_NAME#&quot;>
SELECT 'x'
FROM mk_acct_grp
WHERE coy=&quot;#session.G_COY#&quot;
AND acct_group=&quot;#ACCT_GROUP#&quot;
</CFQUERY>
<CFOUTPUT query = &quot;GetAcctGroup&quot;>
<CFIF GetAcctGroup.x eq 'x'>
<CFCONTENT TYPE=&quot;image/GIF&quot; file=&quot;<CFELSE>
<CFCONTENT TYPE=&quot;image/GIF&quot; file=&quot;</CFIF>
</CFOUTPUT>
</CFSCRIPT>

Well, hope you're having a better day than me!!!

clueless,
hacole
 
FYI....

I've decide the syntax error is actually on my <IMG ...> line..........
 
Thank you all.

due to time constraints, I had to stop trying this method. I ended up adding another .cfm file (much to my dismay) to run the query against the form.value. If there is a problem I take them back to the form, otherwise I proceed to the next file.

Hopefully I'll get some time soon to play with it, because I think it can work. This would work around a problem I think more people could be getting hung up on besides me.

thanks again,
hacole
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top