javascript - How to get the value of a select tag in ReactJs -
i building form
var tableforbasictaskform = react.createclass({ getinitialstate: function() { return { taskname: '', description: '', empcomment: '', emprating: '' }; }, handletasknamechange: function(e) { this.setstate({ taskname: e.target.value }); }, handledescriptionchange: function(e) { this.setstate({ description: e.target.value }); }, handleempcommentchange: function(e) { this.setstate({ empcomment: e.target.value }); }, handleempratingchange: function(e) { this.setstate({ emprating: e.target.selected }); }, render: function() { return ( < div classname = "row margin-top" > < form classname = "col-md-12" > < div classname = "col-md-2" > < input classname = "form-control " type = "text" placeholder = "task name" value = { this.state.taskname } onchange = { this.handletasknamechange } /> < /div> < div classname = "col-md-3" > < textarea classname = "form-control" name = "description" placeholder = "standard discription of task" value = { this.state.description } onchange = { this.handledescriptionchange } /> < /div> < div classname = "col-md-3" > < textarea classname = "form-control" name = "empcomment" placeholder = "employee comment" value = { this.state.empcomment } onchange = { this.handleempcommentchange } /> < /div> < div classname = "col-md-2" > < select value = { optionsstate } classname = "form-control" name = "emprating" onchange = { this.handleempratingchange } > < option value = "" > employee ratings < /option> < option value = "1" > 1 < /option> < option value = "2" > 2 < /option> < option value = "3" > 3 < /option> < option value = "4" > 4 < /option> < option value = "5" > 5 < /option> < /select> < /div> < div classname = "col-md-2" > < input classname = "form-control" type = "submit" value = "post" / > < /div> < /form> < /div> ); } });
so, want know how define select
tag can load value of selected option emprating
variable .
my current code not working properly.
you can use ref
access value input tag in react.
let noderef; <div classname="col-md-2"> <input classname="form-control " type="text" placeholder="task name" ref = { node => { noderef = node; }} value={this.state.taskname} onchange={this.handletasknamechange} /> </div>
now can use noderef
variable value. see more details: https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute
Comments
Post a Comment