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

cflocation like a same page link

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
US
Can I use cflocation to take a user to a specific part of a page...as you would with a same-page link?

I have a dynamic id (cmtid) generated, then use that dynamic id in the cflocation url to take the user to a specific comment on the page.

<cfset pid = 3>
<cfset cmtid = 7>
<cflocation url="thepage.cfm?pid=#pid###cmtid-#cmtid#">

Then on thepage.cfm ...
<a id="cmt-7"></a>
<p>this is where I want the user to be directed</p>

That's basically what I'm trying to accomplish but it's not working. I think I'm creating the cflocation url incorrectly.

Any ideas?
 
Okay, that makes sense. But I'm still getting an error, must be related to the way I'm formulating my url.

My url ends up looking like this: thepage.cfm?pid=1#cmt-15&CFID=8353676&CFTOKEN=57956917

Which produces this error on the details.cfm page:
The error occurred in thepage.cfm: line 41
41 : WHERE svc_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#url.pid#">

Without the #cmt-15 in the url, the page loads without error. If I put a & before #cmt-15, there is no error, but the page doesn't scroll down to the correct anchor name like I need it to.

Any ideas?
 
Hi PushCode,

Instead of:

<cflocation url="thepage.cfm?pid=#pid###cmtid-#cmtid#">

put:

<cflocation url="thepage.cfm?pid=#pid#&cmtid=#cmtid#">

Peter [smile]
 
Sorry, for the relocation I meant:

<cflocation url="redirect.cfm?pid=#pid###cmtid">
 
shoulda done this the first time for ya...

Code:
<cfset pid = 3>
<cfset cmtid = 7>
<cflocation url="thepage.cfm?pid=#pid###cmt-#cmtid#">

Then on thepage.cfm ...
<a name="cmt-7"></a>
<p>this is where I want the user to be directed</p>

Kevin
 
Kevin and peterswan, that is exactly what I have. It's just not working.

I have: <cflocation url="thepage.cfm?pid=#pid###cmt-#cmtid#">

Then on thepage.cfm the url looks like: thepage.cfm?pid=1#cmt-15&CFID=8353676&CFTOKEN=57956917 as mentioned earlier.

This is causing an error in my query on thepage.cfm that uses the url.pid variable.

The error occurred in thepage.cfm: line 41
41 : WHERE svc_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#url.pid#">

Any ideas what's causing the error?
 
Here's the entire query:
Code:
<cfquery name="getSvc" datasource="#app.ds#">
		SELECT svc_id, svc_name, desc,url, ph_area, ph_3, ph_4, adr_str_1, adr_str_2, adr_cty, adr_st, adr_zip, img
		FROM svc_details
		WHERE svc_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#url.pid#">
	</cfquery>

The query works fine if I take out the #cmt- portion of the url, which leads me to believe that it's a problem with the way coldfusion is reading the url. Am I wrong?
 
Thanks, but getting rid of the url scope didn't solve it either.

Here's the entire error:
Invalid data 1#cmt-15 for CFSQLTYPE CF_SQL_INTEGER

It thinks the entire 1#cmt-15 is the url.pid variable, when actually, it should just be 1.
 
> It thinks the entire 1#cmt-15 is the url.pid variable,
> when actually, it should just be 1.

Yes. Review the link. That's what it talks about :) There are several suggestions in the bottom comments.

 
Thanks, but getting rid of the url scope didn't solve it either.

Sorry if I was unclear. I meant CFDump the URL scope on thepage.cfm so you can examine the value of #url.pid#.
Code:
<cfdump var="#URL#">

 
thanks for the clarification starlight.

Using the &# hack proposed from one of the comments in that link did prevent the error. However the page does not automatically scroll down to the appropriate anchor name on the page, it just loads the page at the top like any normal page.

I may be out of luck with this.
 
Did you use addToken="no"? Try also the dummy variable hack.

thePage.cfm?pid=abc&dummyVariable=nothing#cmt-15
 
Actually I just discovered that it works if I remove the &CFID=8353676&CFTOKEN=57956917 stuff from the url!

How do I keep the cfid and cftoken from being added to the url?
 
Nevermind. Got it working. addtoken="no" needs to be in the cflocaton tag as well.

Thanks for the help all!
 
You're welcome. I guess the timing of our posts was off. I felt like we were in echo-canyon for that last part ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top