user3292534
user3292534

Reputation:

pass form data as url to d3.json method

I have an HTML form which has one input. This input I'd like to be a URL from which D3.json method would take it's data for building an illustration.

I'm wondering how can I pass this input? I suppose form's action can help, but I do not know how to pass variables using it.

Upvotes: 0

Views: 621

Answers (1)

Mark
Mark

Reputation: 108557

You can just read the value property of the input and pass that to d3.json...

var myUrl = d3.select('#myTextBox').property('value');
d3.json(myUrl, function(error, json) {
  // do awesome stuff...
});

EDITS

d3.select('#myButton').on('click', function(){
  var myUrl = d3.select('#myInput').property('value');
  d3.json(myUrl, function(error, json) {
      if (error) throw(error);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<input type="text" id="myInput" />
<button id="myButton">My Awesome Action!</button>

Upvotes: 1

Related Questions