- create new project called forms with the following components
- d3.js file
- index.html file with body tag
- main.js file
- link index.html file to d3.js and main.js
In the HTML file.
-
create a form with the
<form>tag. -
create a label element inside of the form
-
create input of type radio
<head> <meta charset="utf-8"> </head> <body> <form> <label> <input type ="radio" name="city_button" value="honolulu" /> Honolulu </label> </form> </body>
Separate with a <br> to create a new line for each city.
<br>
<label>
<input type="radio" name="city_button"
value="chicago" />
Chicago
</label>
-
in main.js, create a variable called buttons.
var buttons -
assign buttons to the result of
d3.selectAll(...
The name of the HTML element you are selecting is called, 'input'.
var buttons = ... fill in this area ...
-
create a named function called, getChange.
function getChange() ... -
in the function, output to console.log,
this.value.
Note: The value comes from the value of the input label.
buttons.on("change", getChange);
- buttons is the variable holding all the input sections
onis a special keywordchangeis a special keywordgetChangeis the name of the function to run.
var buttons = d3.selectAll("input");
function getChange(){
console.log("Got change to " + this.value);
}
buttons.on("change", getChange);


