HREF with named anchor and CF variable

I have a link that contains a variable and an anchor. The anchor is PRAStab + a variable.

Without any additional variables, when this is clicked:
   <a href="dsp_trackingAdminTest.cfm?PRAStab#qry_getTracking.trackingUnitID#">Link</a>

this is the url in the browser:
   http://staffnetdev.rti.org/research/pdo/apps/spdr_rev/dsp_trackingAdminTest.cfm?PRAStab6

This one works.

My problem is, I can't seem to add any additional variables or it stops reading the anchor. When I try to add another variable (sortOrder) like this:
   <a href="dsp_trackingAdminTest.cfm?sortOrder=client_org_name##PRAStab#qry_getTracking.trackingUnitID#">link</a>

The browser reads it like this:
http://staffnetdev.rti.org/research/pdo/apps/spdr_rev/dsp_trackingAdminTest.cfm?sortOrder=client_org_name#PRAStab6

I don't know how to include this anchor along with this variable. I've tried switching the # around. Nothing seems to work.
traportAsked:
Who is Participating?
 
HyperBPPConnect With a Mentor Commented:
Are you expecting the querystring to be sent back to the server?  I believe that anchors are completely client side.  I slapped together a little code that works on IE8 and FF.

When you click a link, it uses javascript to get the sortOrder, and then goes to the anchor.
<script>
var sortOrder = "";
function getSortOrder(queryString){
	sortOrder=getQueryStringKey('sortOrder',queryString);
	sortOrder=sortOrder.split('#')[0];
	alert(sortOrder);
	return sortOrder;
}

function getQueryStringKey(searchKey, queryString){
	if(queryString == undefined){
		queryString = window.location.search.substring[1] || "";
	}else{
		queryString = queryString.split("?")[1];	
	}
	keys = queryString.split("&"); 
	for (i=0;i<keys.length;i++) { 
		key = keys[i].split("="); 
		if (key[0] == searchKey) { 
			return key[1]; 
		}
	}
}
</script>


<cfset qry_getTracking.trackingUnitID = "1234"/>
<cfset test2 = "4321"/>

<cfoutput>
	<a href="dsp_trackingAdminTest.cfm?sortOrder=client_org_name##PRAStab#qry_getTracking.trackingUnitID#" onClick="getSortOrder(this.href)">client_org_name</a><br/>
	<a href="dsp_trackingAdminTest.cfm?sortOrder=client_last_name##PRAStab#test2#" onClick="getSortOrder(this.href)">client_last_name</a>
</cfoutput>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<a name="PRAStab1234">PRAStab1234</a>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<a name="PRAStab4321">PRAStab4321</a>

Open in new window

0
 
HyperBPPCommented:
According to the RCF the URL is split by the fragment identifier first (#), if present, and *then* parsed as an address. It's therefore imperative that the fragment identifier is placed last in the URL, which may also be combined with a query string
0
 
erikTsomikSystem Architect, CF programmer Commented:
you can put it into the variable and then pass it to the url.
<cfset url_variable= ID>

Also i noticed that in your url you have an extra #.

Also in order to pass multiple url variables they need to be separated by &

For example
<a href="page.cfm?Variable1=#id#&variable2="#id2#""
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
HyperBPPCommented:
You might try    <a href="dsp_trackingAdminTest.cfm?sortOrder=client_org_name&1=1##PRAStab#qry_getTracking.trackingUnitID#">link</a>

Since you don't care about the 1=1, it doesn't matter if it gets corrupted.
0
 
traportAuthor Commented:
Thanks all for the replies.

HyperBPP: I don't understand what you're saying. The anchor is the last in the URL here if that's what you mean. Changing it to add the 1=1 doesn't work for some reason, either.

erikTsomik: I'm going to try your suggestion and may not be back until tomorrow just to let you know. I have an extra # b/c that's what you have to have in CFML so that it reads # which I used to indicate it was an anchor (in CFML I have to use double # when I'm w/in cfoutput).
0
 
HyperBPPCommented:
What broswer are you using?
0
 
erikTsomikSystem Architect, CF programmer Commented:
you only need to use double when you need to dispaly 1#
0
 
traportAuthor Commented:
I'm using IE8.
0
 
dwkdCommented:
correct me if i'm wrong but you want the end result to look something like <a href="dsp_trackingAdminTest.cfm?sortOrder=client_org_name#PRAStab12345">link</a>
if so, do something like
<cfset AnchorId = "PRAStab#qry_getTracking.trackingUnitID#">
<a href="dsp_trackingAdminTest.cfm?sortOrder=client_org_name###AnchorId#">link</a>
0
 
traportAuthor Commented:
Ah... thank you! Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.