user2986179
user2986179

Reputation: 13

document.getelementbyid inside onclick of an input element

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

Answers (3)

Sachin Verma
Sachin Verma

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

Sridhar R
Sridhar R

Reputation: 20408

Use this attribute to get value of the radio button

<input type="radio" id="radio" name="packages" onclick="callrest(this.value);"/>

Fiddle

Upvotes: 0

Ankit Tyagi
Ankit Tyagi

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

Related Questions