• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Dynamically show 1 row of a cold fusion query

Guest
Jun 04, 2008 Jun 04, 2008

Copy link to clipboard

Copied

Hey everyone,
A simple question, I am just have a hard time figuring out the most effecient and easy way to do this. Say I have a query like

<cfquery name="getcrap" datasource="users">
SELECT NAME, ID, JOBROLE
FROM PEOPLE
</cfquery>

<select name="listpeople" OnChange="SOME_MAGIC_JS_FUNCTION(this.value)">
<cfloop query="getcrap">
<option value="#getcrap.id#">#getcrap.name#</option>
</cfloop>
</select>
<div id="showdetails">I WANT THE JOB ROLE THE PERSON TO DISPLAY HERE</div>

How can I make that work. Basically a query pulls some values, I loop through the values creating a dropdown list item for each person, and want to show more in depth info on that person when they are selected from the dropdown list. I think I would have to load the data from the cold fusion query into a javscript array or something then display the element of the array signified by the ID passed to the function, but I'm not real sure how to do that. Anybody have any sample code for how to do this?

TOPICS
Advanced techniques

Views

801

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 04, 2008 Jun 04, 2008

Copy link to clipboard

Copied

Javascript.

Adobe has a free library called Spry.

http://labs.adobe.com/technologies/spry/samples/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 04, 2008 Jun 04, 2008

Copy link to clipboard

Copied

Thanks for the reply, I might look at that. I think I am real close using the toscript function. I get a result that looks like
WDDXQuery = new WddxRecordset(); col0 = new Array(); col0[0] = "Bob Jones" .....; Using toscript I can turn the query results into a javascript array, but I can't seem to really do anything with it. Attached is the code I have so far.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 04, 2008 Jun 04, 2008

Copy link to clipboard

Copied

quote:

Originally posted by: kenji776
I think I would have to load the data from the cold fusion query into a javscript array or something then display the element of the array signified by the ID passed to the function, but I'm not real sure how to do that. Anybody have any sample code for how to do this?


That's pretty close. To the best of my knowlege, js only supports 1D arrays, so you would need an array for every query field.

You are attempting something similar to Related Selects. Here is some sample code for that, http://www.pathcom.com/~bracuk/code/RelatedSelects.htm . You'll just have to adapt it to your own requirements.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 04, 2008 Jun 04, 2008

Copy link to clipboard

Copied

Dan, thanks for the info. That link you posed is dead however. I went and checked quick, and it does seem as though Javascript supports multidimensional arrays.
http://www.devx.com/tips/Tip/12455
Unless I'm reading that wrong (I'm sorta a novice programmer, so very likely I misinterpreted that). Can you repost link? Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 04, 2008 Jun 04, 2008

Copy link to clipboard

Copied

I figured it out.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 04, 2008 Jun 04, 2008

Copy link to clipboard

Copied

I've had to implement some dynamic query stuff before and I used 2D arrays. Here's how I would initialize yours:

<script>
var queryArray=[];
<cfloop query="getcrap">
<!---The reason I'm subtracting 1 from the Current Row is because Current Row starts at 1 but js arrays start at 0--->
queryArray[#getcrap.CurrentRow-1#]=[];
queryArray[#getcrap.CurrentRow-1#][0]=#ID#;
queryArray[#getcrap.CurrentRow-1#][1]="#NAME#";
queryArray[#getcrap.CurrentRow-1#][2]="#JOBROLE#";
</cfloop>
</script>

Next, when a user changes the name, retrieve the current value of 'listpeople' (which will be the ID) and search through your js array until you find a match. Then, use the index of the found value to retrieve and set the job role.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 04, 2008 Jun 04, 2008

Copy link to clipboard

Copied

Nice, that is a smooth solution, I like it a lot. If i wasn't so proud of the thing I just found, I would definitely use it, and actually I probably will end up using it once I finish patting myself on the back 😛 Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 04, 2008 Jun 04, 2008

Copy link to clipboard

Copied

LATEST
quote:

Originally posted by: kenji776
Dan, thanks for the info. That link you posed is dead however.

I edited my post, the link now works. What happened was, I pasted the url into the textarea on this site and then added a period to end the sentence. That final period became part of the link, which wrecked it.


Glad you were able to solve your problem on your own though.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation