i have many input fields like this
<input type="radio" name="name" id="name" onchange="enableTxt()" />
when i click this radio button i wanna capture the id of the radio input. i am using the following code
function enableTxt() {
var id = $(this).attr("id");
alert(id);
}
Am getting this error
a.attributes is undefined
HTML:
<input type="radio" name="name" id="name" onchange="enableTxt(this)" />
JS:
function enableTxt(elem) {
var id = $(elem).attr("id");
alert(id);
}
The html
<button class="destroy" id="123">
The jQuery
$('button.destroy').on('click', function(e){
e.preventDefault();
console.log(this.id);
You can pass just the ID from the HTML
<input type="radio" name="name" id="name" onchange="enableTxt($(this).attr('id'))" />
function enableTxt(id)
{
alert(id);
}
pass this to the function
enableTxt(this)
function enableTxt(item) {
var id = $(item).attr("id");
alert(id);
}
Try this
alert($("input:radio").attr('id'));
Another option is with JQ
$("#name").on('onchange',enableText);
With this your object will be the current this