I want to get the value of the current <input type="radio">
element 开发者_开发百科in its onClick
.
I need something like:
<input type="radio" name="myRadio" value="something" onClick="theValueOfThisInput">
I can't use getElementById()
because all my radio buttons have the same id.
I've currently done it by wrapping all the inputs in a <div>
and getting the elements of the <div>
by index, but I won't even bother posting it because I don't think it would be helpful to anyone.
Can someone recommend a good way to do this ?
Thanks,
Have you tried
this.value;
?
this.value
should certainly work.
Try:
<input type="radio"
name="myRadio"
value="something"
onclick="alert(this.value)" />
And the 'alert' function can be replaced with whatever function call you wish.
精彩评论