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!

Passing a CF variable to a Javascript 4

Status
Not open for further replies.

arcangel

Programmer
Aug 2, 1999
6
0
0
US
In the examples below, example 2 works, but example 1 DOES NOT. I need #2 to work. Any ideas?? THanx.<br>
<br>
Example 1<br>
-----------------<br>
&lt;CFSET sOutput="Hello world"&gt;<br>
&lt;SCRIPT LANGUAGE=JAVASCRIPT&gt;<br>
newWindow.document.writeln(#sOutput#)<br>
&lt;/SCRIPT&gt;<br>
<br>
Example 2<br>
-----------------<br>
<br>
&lt;SCRIPT LANGUAGE=JAVASCRIPT&gt;<br>
newWindow.document.writeln('Hello world')<br>
&lt;/SCRIPT&gt;<br>

 
Need to put the quotes around the #sOutput# like so:<br>
<br>
newWindow.document.writeln('#sOutput#')<br>

 
hi,<br>&nbsp;&nbsp;I also wanted to know if a JS prog can hold a CF variable ?<br>Here JS is just outputting a CF variable .... but can I pass the CF variable to a JS variable ???<br><br>[V]
 
Re firesign's follow-up query:<br><br>cfhomer's advice applies here too, e.g.<br><br>&lt;CFSET sOutput=&quot;Hello world&quot;&gt;<br>&lt;SCRIPT LANGUAGE=JAVASCRIPT&gt;<br><b>var X = &quot;#sOutput#&quot;</b><br>&lt;/SCRIPT&gt;<br><br>
 
yeah, I thought of that.<br>Although it really never hit me until I read what you wrote.<br><br>ok, I have a array in CF say #sOUTPUT[x]#<br><br>now, I want to transfer all these items to JS for calculation.<br><br>lets say, var n[x]<br><br>CF has a bunch of items&nbsp;&nbsp;that it pulled from the Database and now wants to transfer it to JS for furthur calculations.<br>those items should look like this :-<br>--------------------------------<br>n[1]=&quot;Business &quot;;<br>n[2]=&quot;Children's &quot;;<br>n[3]=&quot;Desktop Publishing &quot;;<br>n[4]=&quot;Developer Tools &quot;;<br>n[5]=&quot;Educational &quot;;<br>---------------------------------<br><br><br>If i can do this.. then it would be great.<br>can it ?<br>I have an idea that im going to try out now....<br><br><br> <p> <br><a href=mailto: > </a><br><a href=
 
the only way i managed to do it (surely not the correct way ;) but hey, it works ;)) is something like this :<br><br>&lt;script langage=&quot;javascript&quot;&gt;<br>var n=new Array(#your_query.Recordcount#)<br>&lt;cfloop query=&quot;your_query&quot;&gt;<br>n[#CurrentRow#]=&quot;#name_of_col[CurrentRow]#&quot;<br>&lt;/cfloop&gt;<br>&lt;/script&gt;
 
hm... i'm confused ~_~<br>so what exactly is the correct answer?<br>put the quotes around the #var# like so:<br><br>newWindow.document.writeln('#var#')<br><br>
 
yes rachel there's nothing more to do (weeeeelll, as long as your cf variable doesn't contain any ' or &quot; because it might confuse jscript ... but you still can replace them before ;] - use CFREPLACE )
 
firesign:
are u sure we can use '<cfloop query=&quot;your_query&quot;>'
within the <script language=&quot;Javascript&quot;> ??
Can we do this:

<script langage=&quot;javascript&quot;>
function assignVar() {

int i
new array jsvar

for i=1 to i=5
jsvar = &quot;#sOutput#&quot;

// to assign CF array values to js array
}

</cfloop>
</script>

Pls correct me if i'm wrong, thanx!
 
yes i'm sure, and yes i've done this yet, and yes it works fine ! but in the way i told you : you have to use the cf control structure as it's SERVER side and as such will b done before the jscode that is CLIENT side - your way (using js control structure) won't work.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top