Select to view content in your preferred language

How to embed an attribute value in a hyperlink within infoWindow/content/href

1098
5
02-10-2011 09:27 AM
WendiYoung
Emerging Contributor
I am very new to ArcGIS API for JavaScript so bare with me.

I would like to use a value from an attribute such as a "name" to reference a text
file within the content of an infoWindow such as:

<a href="http://foobar.com/name1/name1.txt"> Name: " + attrs.Name + ".txt</a>"

where
mainlink = "http://foobar.com/"
end_of_link = attrs.Name + "/" + attrs.Name + ".txt"
link = mainlink + end_of_link

and the variable "link" is substituted above for "http://foobar.com/name1/name1.txt".

Can someone help me with the syntax in the above reference using the link variable?

Thanks.
0 Kudos
5 Replies
KellyHutchins
Esri Frequent Contributor
The following sample in the developer help shows how to use attribute information in a hyperlink:


http://help.arcgis.com/EN/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/fl_infowindow....
0 Kudos
EmilyLaMunyon
Deactivated User
Hello,

I am also struggling with this. The link to the sample seems to be broken, is there another sample that demonstrates this somewhere else?

Thanks!
0 Kudos
derekswingley1
Deactivated User
To do this, you want to build an HTML string. If you want markup that looks like:
<a href="http://www.server.com/path/file.txt">link text</a>


and you have an attributes object that looks like:
{ 
  "path": "some-web-server-folder",
  "file": "data"
}


You would do this:
var anchor = "<a href='http://www.server.com/" + attr.path + "/" + app.file + ".txt'>link text</a>";


Managing those single and double quotes can get unwieldy. If you're building big strings, check out dojo.string.substitute to use templates which usually results in cleaner code.
0 Kudos
EmilyLaMunyon
Deactivated User
Thanks a million Derek.;)

So, I have something like this working on infoWindows throughout my code, but for some reason it is not working on others. Is this syntax correct? When this is not working, the link does not substitute the fields correctly, it just keeps it literal. Is there more documentation on creating links using fields this way?


map.infoWindow.setContent("<a href='http://surveyor.slco.org/gis/map/Corner_Reports/surveysimage.cfm?subdir=${subdir}&page_id=${page_id}.pdf'>PDF</a>");
0 Kudos
derekswingley1
Deactivated User
setContent requires a string, it doesn't do substitution for you.

For more info, refer to our conceptual help. Specifically, the format info window content section. Lots of other great info pertaining to popup/info window content in that area as well.
0 Kudos