I have a simple form in my render
function, like so:
render : function() {
return (
<form>
<input type="text" name="email" placeholder="Email" />
<input type="password" name="password" placeholder="Password" />
<button type="button" onClick={this.handleLogin}>Login</button>
</form>
);
},
handleLogin: function() {
//How to access email and password here ?
}
What should I write in my handleLogin: function() { ... }
to access Email
and Password
fields ?
Output image attached here
An alternative approach is to use the
ref
attribute and reference the values withthis.refs
. Here is a simple example:More info can be found in the React docs: https://facebook.github.io/react/docs/more-about-refs.html#the-ref-string-attribute
For a lot of the reasons described in How do I use radio buttons in React? this approach isn't always the best, but it does present a useful alternative in some simple cases.
Also, this can be used too.