I want to put either an href link or a button in a infoWindow in one of my javascript mobile apps. The info window tells the cell value of a feature layer that is clicked on. Then I have added an infoWindow that calls a functions which should run a geoprocessing task. The problem is the link cannot seem to find the function no matter where I put it in my code. I am getting an error "Uncaught ReferenceError: MyFunction is not defined. Is it not possible to call a javascript function from an infoWindow?
Have you seen this sample that contains a link to a function in a infoWindow?
Thanks for the reply Ken, I did see that sample, but was unable to figure out how to get that link into my infoWindow just by looking at the code. I am able to get an href link into my infoWindow, but I am not certain why the href link isn't able to call any functions within my javascript.
Can you post your code?
If it helps, I do this in one of my applications. The infoWindow appears and has two buttons that the user can click which fires off a function that generates a report. Here's the entire function for the content of my infoWindow:
function SetSwmPopupInfo(graphic) {
var fullAttr = graphic.attributes;
var rptParam, content, theProjID, theTipType;
var theCipID = fullAttr.ProjectNo;
rptParam = "'" + graphic.attributes.OBJECTID + ',' + graphic.geometry.type + ',' + "SWM" + "'";
rptProjectName = graphic.attributes.ProjTitle;
if (theCipID.length > 1) {
theProjID = fullAttr.ProjectNo;
} else {
theProjID = "Unknown";
}
content = '<table width=\"100%\"><tr><td valign=\'top\' style=\"font-weight:bold;padding-left:3px;padding-right:3px\">Project Name:</td><td valign=\'top\' style=\"padding-left:3px;padding-right:3px\">' + fullAttr.ProjTitle + '</td></tr>';
content = content + '<tr><td valign=\'top\' style=\"font-weight:bold;padding-left:3px;padding-right:3px;vertical-align:top\">CIP Project ID:</td><td valign=\'top\' style=\"padding-left:3px;padding-right:3px;vertical-align:top\">' + theProjID + '</td></tr>';
content = content + '<tr><td valign=\'top\' style=\"font-weight:bold;padding-left:3px;padding-right:3px;vertical-align:top\">Type of Project:</td><td valign=\'top\' style=\"padding-left:3px;padding-right:3px;vertical-align:top\">' + fullAttr.Category.toProperCase() + '</td></tr>';
content = content + '<tr><td colspan=\"2\" align=\"center\"><br/><button id=\"reportButton\" type=\"button\" onclick=\"getTractProjectReport(' + rptParam + ')\">View a Summary Demographic Report (Census Tract Level)</button></td></tr>';
content = content + '<tr><td colspan=\"2\" align=\"center\"><button id=\"reportBlockButton\" type=\"button\" onclick=\"getBlockProjectReport(' + rptParam + ')\">View a Summary Demographic Report (Block Group Level)</button></td></tr></table>';
return content;
}
Make sure the function you are trying to call is located within the function of your AMD requires:
require(["esri/map""], function("Map") {
...
//Place your called function inside and at the end of this space
});