Reputation: 13
I have a input radio element like this:
<input type="radio" value="" name="radiobtn" />
on click of this radio button I should be able to pass the value of radio button to js function, i tried like this:
<input type="radio" id="radio" value="" name="packages" onclick="callrest(document.getElementById('radio')"/>
but it is saying "undefined", please help me
Upvotes: 0
Views: 209
Reputation: 3802
You can use this
or getElementById
function as you used.
but you were missing )
syntax in calling function.
<input type="radio" id="radio" value="" name="packages" onclick="callrest(document.getElementById('radio'))"/>
Upvotes: 0
Reputation: 20408
Use this
attribute to get value of the radio button
<input type="radio" id="radio" name="packages" onclick="callrest(this.value);"/>
Upvotes: 0
Reputation: 2375
Use like this here 'this' refer to current element :
<input type="radio" id="radio" value="" name="packages" onclick="callrest(this.value);"/>
Upvotes: 1