Help - Search - Members - Calendar
Full Version: Perform query onChange
W3Schools Forum > Server Scripting > ColdFusion
vchris
I am working on a complicated form. Now there is a select and depending on the choice of the select I have to return different records from the db. Is there a way to create a query that is only executed onChange event without page reload?

<cfscript> maybe? I never worked with this tag before.
Skemcin
it sounds like you are looking for a solution that uses either Flash Remoting or AJAX.

I'm not completely following your request, but if one drop box is controlling the contents of another drop box, these are the only four options I know of:
a.) use flash forms and flash remoting (no post back)
b.) use html forms and AJAX (no post back)
c.) use html or flash forms and create a post back
d.) run all the queries hen the page loads and use javascript to populate the correct drop box for each selection (too much processing for large drop box selections)

Is this pertenant to the application you are trying to build?
vchris
Yes. That's basically it. If they choose option 1 in select 1 then select 2 will have choices relative to select 1 option 1. Should have only around 3-4 options in the second select.

Is AJAX like javascript?
Skemcin
yes, it is a combination of server-side and client-side scripting. I have not used it yet so I am not much help there.
sad.gif
scott100
QUOTE (vchris @ Nov 14 2006, 08:54 PM) *
Yes. That's basically it. If they choose option 1 in select 1 then select 2 will have choices relative to select 1 option 1. Should have only around 3-4 options in the second select.

Is AJAX like javascript?


http://www.w3schools.com/ajax/ajax_database.asp

When you select from the dropdown the record from the database changes (without the page loading), i guess you make a second dropdown with this new information if you wish.

AJAX is partially java script: Asynchronous JavaScript And XML wink.gif

But hey i ain't had time to learn AJAX yet sad.gif or Coldfusion tongue.gif So i'm outta here! laugh.gif
vchris
I'll take a look at that tomorrow morning at work. Thanks!
vchris
Here's what I was looking for!

http://www.indiankey.com/cfajax/examples/list.htm

Now just need to understand it and make it work.

EDIT:
Even better http://www.fusionauthority.com/Techniques/...ldFusion-Part-I

Anyone know what they mean by:
QUOTE
The code to achieve this in CFAJAX would look something like this (omitting the links to the include files that come with CFAJAX, as they depend on the developer's configuration):

I figured out that I need a library for ajax to work. I know Yahoo has a ajax library. Anyone know how to include and what file exactly to include? Do I have to download some files or can I just link to a site?
Skemcin
what you bolded in your quote is basically telling you that all the files can be used as is. however, the <cfinclude> files that they provide might have to be modified (just the structure of the file path) so that you do not get a "template not found" ColdFusion error.

If you get a clean page of AJAX and ColdFusion, I'd be interested in seeing/studying it. I know AJAX is only compatible with IE and FF, but it is something I'd like to consider toying with on a few intranet applications.
(thanks in advance)
vchris
it's only compatible with IE and FF!!! oh really? I didn't know that. Tell me what options do I have when I want to change the options in a select depending on the selected option in another select? I don't want any page reload.
Skemcin
Refer to the second post - those are the only methods I am aware of.
vchris
How would I do your D option in your second post?

I know I can get all the records for that drop down but how can I only choose the ones needed with javascript?
Skemcin
QUOTE (vchris @ Nov 16 2006, 07:46 AM) *
How would I do your D option in your second post?

I know I can get all the records for that drop down but how can I only choose the ones needed with javascript?

Sorry for not getting back to this, if it is still any help, here is the reply.

For option D, where you run all your queries then use javascript . . .

Lets say you have 7 queries that each list the respective countries on the various continents. In the first drop box, you would simply list all seven continents. Using javascript and the onchange function, you can determine which continent a user selected. Now, when the page loaded to begin with lets say you build a on row table with two columns. The left column is the drop box for the continents and the right column is the dynamic drop box that displays the respective country list for the selected continent. When the page loads, pre-build all your form optin groups - so you have 7 form option groups. Now, wrap each of them in a <div> that has a unique ID defined. Each <div> is then placed in that right column and each <div> is defined as such <div style="display:none;">. Use my show/hide function available in the javascript snippet forum and you can effectively show/hide each group of countries based on the continent you select.

Let me know if this makes sense.
vchris
Hehe... Don't worry it's resolved. I should of change my first post to say so.
Skemcin
glad you found a solution.
:-)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.