Reputation: 835
The input is :
<input type="button" value="O" name="<?php echo $v[$i]['t']; ?>" onclick="javascript:test_parent();">
Suppose there are a lot of button with different attribute name.I need to create a function test_parent()
and in this function I need to extract the name of button that I clicked. Anyone can help me?
Upvotes: 0
Views: 57
Reputation: 2480
Selecting Input Value in Input Field, Demo
function myFunction() {
alert(document.getElementById('inputId').value)
}
Upvotes: 0
Reputation: 7878
I would recommend you to avoid the inline js. You can attach an event-listener instead:
$(document).ready(function(){
$('input[type="button"]').on('click', function (){
alert($(this).attr('name'));
});
});
Reference
Upvotes: 1
Reputation: 1531
The following code should work for you.
HTML
<input type="button" value="O"
name="<?php echo $v[$i]['t']; ?>"
onclick="javascript:test_parent(this);">
Javascript
function test_parent(input){
var name = $(input).prop("name");
}
See a demo here http://jsfiddle.net/6georz5m/
Upvotes: 0
Reputation: 1217
I think this may be your answer
$('input[type="button"]').on('click', function (){
var name = $(this).attr('name');
alert(name);
});
Upvotes: 0