reactjs - Get the value of checkbox using ref in React -
is there way value of checkbox using ref in react. normal way return value "on" me.
var myform = react.createclass({ save: function(){ console.log(this.refs.check_me.value); }, render: function(){ return <div><h1>myform</h1> <div classname="checkbox"> <label> <input type="checkbox" ref="check_me" /> check me out </label> </div> <button classname="btn btn-default" onclick={this.save}>submit</button> </div> } });
for checkbox, use "checked" instead of "value":
var myform = react.createclass({ save: function () { console.log(this.refs.check_me.checked); }, render: function () { return <div><h1>myform</h1> <div classname="checkbox"> <label> <input type="checkbox" ref="check_me" /> check me out </label> </div> <button classname="btn btn-default" onclick={this.save}>submit</button> </div> } });
as result:
Comments
Post a Comment