How to update text input content with d3?

I am trying to create a text input control in D3 that needs to insert data into text input. I can set the initial value with

d3.selectAll('#textfield')
    .data([number])
    .attr('value', function(d) { return d })

but it is useless if someone edits the text and then tries to perform an external update. Is there a way to set the content to some arbitrary value?

I have code in JsFiddle .

Update:

I found a workaround :

var node = d3.selectAll('#textfield')
    .data([number])
    .node()
node.value = number

But I'm not sure if this is the right approach. Any clues?

+3
source share
3 answers

value, value , setAttribute ( d3 ).

, d3:

d3.selectAll('#textfield')
    .data([number])
    .each(function (d) {
        this.value = d;
    });

: http://jsfiddle.net/LGtDD/3/


, (, , ) JS , . D3 :

document.getElementById('textfield').value = number;
+2

:

function changeValue() {
    var number = Math.round(Math.random()*100);
    d3.select('#textfield')[0][0].value = number;
}
0

You can set the text input value with

d3.select('#textfield').property('value', "<your desired text>");
0
source

All Articles