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

Using cold fusion in javascript

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
Hi every body
I want use clodfusion in javascript code
there is no problem
but when i try this code i have error

<cfset test=document.aaa.bbbb.value>
the error
{{{An error occurred while evaluating the expression:


test=document.aaa.bbbb.value}}}





How coldfusion read variable in java script




Thanks for all


 
Check out this FAQ. It should answer your question.

faq232-171 Calista :-X
Jedi Knight,
Champion of the Force
 
The FAQ doesn't mention this, and I haven't tried it, but you should be able to send Javascript data to the next CF page by serializing it (using Javascript) and de-serializing it (using <CFWDDX>). Look in your CF documentation at .../CFDOCS/weisswddx.htm or search the help files for &quot;wddx&quot;. ColdFusion comes with Javascript code (.../cfide/scripts/wddx.js) to serialize data.
 
Thanks for you
but the problem is
when i write this code in javascript

<cfquery ................>
select *
from table
where x=document.form_name.combobox_name.value
</cfquery>
sql statment can't read document.form_name.combobox_name.value
why
plz

note: tha javascript code excute onchange the combobox
 
I'm no expert at JavaScript (or CF, for that matter!), but I really wrestled with this issue. The one thing iza (the one who wrote the FAQ I directed you to) kept hammering at me about was, JS is client-side, CF is server-side. Therefore, I don't think you can perform CF querys in JS. You can use the variables, and some of the CF tags, but I don't think you can use querys.

Anyone else have any other ideas? Calista :-X
Jedi Knight,
Champion of the Force
 
I'm no expert either, but I know that Calista's emphasis is correct. You can't do CF database queries with Javascript because CF operates on the server and Javascript operate on the client. Neither can you manipulate the browser with CF, for the same reasons. Although CF can use the values of form fields (such as your combobox), it does so on the server. That means that the page containing the form field must be submitted to the server where CF does something with it and then sends it back to the browser. You can, however, use CF variables within Javascript because the CF variables are evaluated before the page containing the Javascript is sent back to the browser. Example,

<script language=&quot;javascript&quot;>
var username = '#cgi.remote_user#';
</script>

Clarification on my earlier post. The file that I referred you to, .../CFDOCS/weisswddx.htm, is part of CF 4.5 documentation. It doesn't exist in 5.0. Try using the search facility of the CF documentation and search for WDDX. You will find information and examples of how to transfer Javascript data to ColdFusion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top