简体   繁体   中英

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

此处使用的用法'this'是指当前元素:

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

Use this attribute to get value of the radio button

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

Fiddle

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'))"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM