I have a JSON object full of County names and I want to call it using SSJS then populate a dropdown list in HTML using the Data from the JSON.
JSON looks like this
[
"AZ - Maricopa",
"AZ - Pima",
"CA - Alameda",
"CA - Contra Costa",
"CA - El Dorado",
"CA - Los Angeles",
"CA - Orange",
"CA - Placer",
"CA - Riverside",
"CA - San Diego",
"CA - San Mateo",
"CA - Santa Clara",
"CO - Adams",
"CO - Arapahoe",
"CO - Boulder",
"CO - Broomfield",
"CO - Douglas",
]
The SSJS call would look like this
%%[ set @JSON = HttpGET("http://some-url-that-returns-json") ]%%
<script runat="server">
Platform.Load("Core", "1")
// get JSON from ampscript
var jsonObj = Variable.GetValue("@JSON");
var evaluatedJSON = eval("(" + jsonObj + ")");`
</script>
The HTML would look like this
<html>
<select class = "county dropdown" name="county" data-placeholder="select a county" required>
<option value="" >County Name</option>
</select>
</html>
And the SSJS populating the dropdown HTML from the JSON would look like this
<script>
var select = $("select.country");
for(var i = 0; i < jsonObj.length; i++) {
var opt = document.createElement('option');
opt.innerHTML = jsonObj[i];
opt.value = jsonObj[i];
select.append(opt);
}
<script>
I am not sure this will work so far but this is how I think it will be set up
The next part will be difficult since I need to pass it through AMPscript following this syntax
SET @AOI = CONCAT(@AOI, IIF(RequestParameter('AZ - Apache') == 'AZ - Apache', 'AZ - Apache;', ''))
SET @AOI = CONCAT(@AOI, IIF(RequestParameter('CA - Alameda') == 'CA - Alameda', 'CA - Alameda;', ''))
And so forth for every County.
I am thinking of using a THIS statement since that would make sense and I wouldn't have to write every possible out look. Since I want this to be dynamic in case the JSON file changes.
SET @AOI = CONCAT(@AOI, IIF(RequestParameter(THIS) == 'THIS', 'THIS;', ''))
Is it possible using AMPScript?
@AOI
variable? Is it creating a delimited list? If so, what is the purpose of this list and/or what do you envision the logic behind it being? Is it on the form page, or the processing page? Without further information on this aspect, I am not sure how to help you solve for it.@AOI
variable is to create a list of areas of interest, this could multiple locations or just one. The logic behind the list is to record it when the user submits based off the dropdown list created from the JSON. I dont want have to update the@AOI
of all the possible locations it could be, I want it to just submit based off what the user select.