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

Referencing Javascript variables in Coldfusion

Status
Not open for further replies.

tempoman

Programmer
May 9, 2000
41
0
0
AU
I am trying to pass the value from one drop down box to populate the second box using cfquerys.

for example if I select Land Vechicles in 1st list it will allow me to select land vehicles only in the 2nd list.

Can this be done?

Here is an example of my code:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function SelectChange(RackID)
{
var FormAPD1 = RackID;
alert(FormAPD1);
}

</SCRIPT>

<select name=&quot;emptyrack&quot; size=&quot;1&quot; onchange=&quot;javascript:SelectChange(document.assignempty.emptyrack.options[document.assignempty.emptyrack.selectedIndex].value)&quot;>

<option>Select</option>
<cfoutput query=&quot;emptyboxes_rack&quot;>
<option value=&quot;#RackID#&quot;>
#RackID#
</option>
</cfoutput>
</select>

I want to access the RackID for the next select list.

Can someone help me please

Thanx

Richard
 
First a little note: as you have used it, &quot;document.assignempty.emptyrack&quot; can be referred to as &quot;this&quot;. When used in an event handler attribute of a form element, &quot;this&quot; refers to the form element. Thus, you could write:

onchange=&quot;javascript:SelectChange(this.options[this.selectedIndex].value)&quot;

Now on to your question:

(1) I'm not sure why your are doing the alert(). Is this just dummy code so that you can see if it's working?

(2) When the user selects from the first list, do you want another (existing) list on the same page to be populated accordingly, OR do you want another page to be loaded with the second select list (populated accordingly)?
 
Yes the alert() is just to see if I can pass the variable.

I would like an existing list on the same page to be populated depending on what the user has select on the previous list.

Thanx for you help

Richard
 
Ok. You will have to use Javascript, which means that you must retrieve all the relevent data a put them into Javascript arrays. Then, when the user selects an element from list1, your Javascript populates (or re-populates) list2. The main thing to note is that you must do all the CF queries that you will need ahead of time (on the server, before the page is sent to the prowser) as you normally would do; then you need to put the results of the queries into Javascript data structures (probably arrays). You do that with <CFWDDX>.

Point your browser to CFDOCS and search for WDDX. Read documents having to do with moveing data across the Web or between Javascript and ColdFusion. There is an excellent document in the ColdFusion 4.5 DOCS at &quot;/CFDOCS/weisswddx.htm&quot;, but is doesn't exist in CF 5.0.
 
Hey, a440guy! Guess I should have read this post before responding to Romario. I finally understand what you're getting at. I accomplished this goal by hard coding the arrays in JS. No one could tell me how to retrieve the data from the database. In my case, I was making a room reservation system, and I wanted the dropdown list for the ending time to jump to half an hour past the beginning time the user chose. Since times of day aren't real likely to change, hard coding it wasn't a particular problem, but I'll keep this in mind for future reference where it might make a difference. Calista :-X
Jedi Knight,
Champion of the Force
 
Hey, Calista!

I'm glad I could help. I'm just learning this stuff too, so it is gratifying to be able to help someone else. And, thank you too for all your help on this forum. You have help me many times (when you didn't even know you were doing so) through your posts on various topics.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top