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

CFLOOP & Popup window! 1

Status
Not open for further replies.

aleci

Programmer
May 22, 2001
40
GB
hi,
im trying to use a CFLOOP tag around a JS popup window function but it seems to be failing . Does anybody have any experience with this - is it possible?

My code is as follows:

<cfoutput>
<cfloop query=&quot;getnews&quot; startrow=&quot;1&quot; endrow=&quot;3&quot;>

<script language=&quot;JavaScript&quot;>
function topWindow1(){popup = window.open(&quot;#link#&quot;,&quot;&quot;,&quot;height=600,width=700,scrollbars=yes&quot;);}
</script>


<A HREF=&quot;javascript:topWindow1();&quot;>go!</a>
</cfloop>
</cfoutput>


The problem is that the #link# is the same for all 3 popups-the last record in the query.
Thanks!
 
-> try #getnews.link# - try a simple cfoutput just to check if the values are correct - try with the row number
-> also be careful that this will open 3 pop ups
-> a good way to check what's actually going on is to view-source on the generated page

i've been using a lot javascript inside cf and it was working fine (provided you remember this : js is CLIENT side whereas cf is SERVER side)
 
To update:
I have the following code which generates 3 popups for each clicked title link ! - whereas i need 1 popup to each associated hyperlink.

<cfoutput query=&quot;getnews&quot; maxrows=&quot;3&quot;>

<script language=&quot;JavaScript&quot;>
function topWindow1()
{<cfloop query=&quot;getnews&quot; startrow=&quot;1&quot; endrow=&quot;3&quot;>
popup = window.open(&quot;#link#&quot;,&quot;&quot;,&quot;height=600,width=700,scrollbars=yes&quot;);
</cfloop>
}
</script>

<A HREF=&quot;javascript:topWindow1);&quot;>#title#</a> </cfoutput>
 
what you write will generate is :
<script language=&quot;JavaScript&quot;>
function topWindow1()
{
popup = window.open(&quot;link1&quot;,&quot;&quot;,&quot;height=600,width=700,scrollbars=yes&quot;);
popup = window.open(&quot;link2&quot;,&quot;&quot;,&quot;height=600,width=700,scrollbars=yes&quot;);
popup = window.open(&quot;link3&quot;,&quot;&quot;,&quot;height=600,width=700,scrollbars=yes&quot;);
}
</script>

so that's totally normal if it opens 3 popups for each clicked link, as you call this function for each clicked link

i don't understand WHICH popup you want to open when the link is clicked, so you need to give a little more explainations so that i can fully help you !
 
hi iza ,
sorry for not being clear.
I have 3 URL links stored in DB (fieldname:link) together with 3 headlines (fieldname:title)
which correspond to each other (they're news headlines).

What i want to happen is to click the 'go' hyperlink next to a headline and see the corresponding news story popup.

What is happening in the following code is that while the headlines are looped through perfectly in the <cfoutput>
tag, the &quot;go&quot; link takes me to the last URL in the DB (the 3rd one) for all 3 headlines.
So it is not being looped and outputted as i would have hoped.


<CFOUTPUT query=&quot;getnews&quot;>

<script language=&quot;JavaScript&quot;>
function topWindow1(){popup = window.open(&quot;#link#&quot;,&quot;&quot;,&quot;height=600,width=700,scrollbars=yes&quot;);}</script>

<u><font color=&quot;Red&quot;>#title#</u></font>

<a href=&quot;javascript:topWindow1();&quot;>go!<br><br></a></font>

</cfoutput>


Hoping you have any ideas!
 
Aleci!

I think your solution is pretty easy:
<CFOUTPUT query=&quot;getnews&quot;>

<script language=&quot;JavaScript&quot;>
function topWindow#CurrentRow#(){popup = window.open(&quot;#link#&quot;,&quot;&quot;,&quot;height=600,width=700,scrollbars=yes&quot;);}</script>

<u><font color=&quot;Red&quot;>#title#</u></font>

<a href=&quot;javascript:topWindow#CurrentRow#();&quot;>go!<br><br></a></font>

</cfoutput>

This way you will create a variable javascript function name. I think the problem was that the brwoser was getting confused by having 3 different functions with the same name (i.e. topWindow1).

Try it and tell me if it works,
Thx,
Chris
 
Chris!
Works perfectly, and is beautiful in its simplicity!
I was just getting into writing loops and queries within loops etc, so you saved me a heck of a lot of time

Many thanks and you get my vote!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top