Add form below the SVG viewport by using JavaScript.
- append additional elements to HTML
<body> - review radio buttons
-
Create a new function in your main JavaScript file called createButtons.
-
The function receives the array of cities.
-
use d3.select to select the body and append a form
-
create a new variable form and assign it to the the result of d3.select...
function createButtons(cities){ var form = d3.select("body").append("form"); }
- pass the function the var cities.
- run the function below the area you append "svg" to "body"
form.append("label").append("input");
form.append("label").append("input")
.attr("type", "radio")
.attr("name", "city_button")
.attr("value", "honolulu");
Use the array of cities to create buttons for each city
for (var index = 0; index < cities.length; index++){
form.append("label").append("input")
.attr("type", "radio")
.attr("name", "city_button")
.attr("value", cities[index]);
}
function getCityChange(){
console.log(this.value);
}
Make sure you run the function after you create the buttons in HTML.
createButtons(cities);
// selecting "input" must be below createButtons
var buttons = d3.selectAll("input");
buttons.on("change", getCityChange);
function getCityChange(){
var nameOfCity = this.value;
return nameOfCity;
}
Test.
var currentCity = buttons.on("change", getCityChange);
- comment out for loop in promise
- pass currentCity to drawCircle function
- drawCircle receives cityName instead of cities




