First of all, i believe that you don't really need that evaluating of code, that is written in ur onclick attribute. Better write a selector in a custom attribute and then do with it whatever you want in your function.
But if you really want to do what you have asked: (try Get3)
for (var i = 0; i < document.getElementsByTagName("input").length; i++) {
document.getElementsByTagName("input")[i].onclick = function(){
alert(this.getAttribute("attribute")); eval( this.getAttribute("attribute"));
};
}
<apex:form >
<c:AutoCompleteV2 allowClear="true" importJquery="true" labelField="name" SObject="Quote_Line_Item__c" valuefield="name" targetField="6" style="width:175px" inputFieldId="Name" />
<input type="button" value="GET" id="0" attribute="$('input[id$=inputFieldId]').val()"/>
<c:AutoCompleteV2 allowClear="true" importJquery="true" labelField="name" SObject="Quote_Line_Item__c" valuefield="name" targetField="5" style="width:175px" id="Name1"/>
<input type="button" value="GET" id="0" attribute="$('input[id$=targetField]').val()"/>
<c:AutoCompleteV2 allowClear="true" importJquery="true" labelField="name" SObject="Quote_Line_Item__c" valuefield="name" targetField="4" style="width:175px" inputFieldId="Name2"/>
<input type="button" value="GET1" id="1" attribute="$('input[id$=valuefield]').val()"/>
<c:AutoCompleteV2 allowClear="true" importJquery="true" labelField="name" SObject="Quote_Line_Item__c" valuefield="name" targetField="3" style="width:175px" inputFieldId="Name3"/>
<input type="button" value="GET2" id="2" attribute="$('input[id$=valuefield]').val()"/>
<c:AutoCompleteV2 allowClear="true" importJquery="true" labelField="name" SObject="Quote_Line_Item__c" valuefield="name" targetField="2" style="width:175px" inputFieldId="Name4"/>
<input type="button" value="GET3" id="3" attribute="console.log(1)"/>
</apex:form>
or jquery version
$( document ).ready(function() {
$( "input" ).click(function() {
alert($(this).attr('attribute'));
$.globalEval($(this).attr('attribute') );
});
});
But i'd recommend you to review your task and use a structure like this: input gets the value of the attribute of the element with id=Name+input.id
for (var i = 0; i < document.getElementsByTagName("input").length; i++) {
document.getElementsByTagName("input")[i].onclick = function(){
alert(document.getElementById("Name"+this.getAttribute("id")).getAttribute(this.getAttribute("attribute")));
};
}
<apex:form >
<c:AutoCompleteV2 allowClear="true" importJquery="true" labelField="name" SObject="Quote_Line_Item__c" valuefield="name" targetField="6" style="width:175px" inputFieldId="Name" id="Name0"/>
<input type="button" value="GET" id="0" attribute="inputFieldId"/>
<c:AutoCompleteV2 allowClear="true" importJquery="true" labelField="name" SObject="Quote_Line_Item__c" valuefield="name" targetField="5" style="width:175px" id="Name1"/>
<input type="button" value="GET" id="0" attribute="targetField"/>
<c:AutoCompleteV2 allowClear="true" importJquery="true" labelField="name" SObject="Quote_Line_Item__c" valuefield="name" targetField="4" style="width:175px" inputFieldId="Name2" id="Name2"/>
<input type="button" value="GET1" id="1" attribute="allowclear"/>
<c:AutoCompleteV2 allowClear="true" importJquery="true" labelField="name" SObject="Quote_Line_Item__c" valuefield="name" targetField="3" style="width:175px" inputFieldId="Name3" id="Name3"/>
<input type="button" value="GET2" id="2" attribute="SObject"/>
<c:AutoCompleteV2 allowClear="true" importJquery="true" labelField="name" SObject="Quote_Line_Item__c" valuefield="name" targetField="2" style="width:175px" inputFieldId="Name4" id="Name4"/>
<input type="button" value="GET3" id="3" attribute="importJquery"/>
</apex:form>
jquery
$( document ).ready(function() {
$( "input" ).click(function() {
alert($("#Name"+$(this).attr('id')).attr($(this).attr('attribute')));
});
});
need values of c:AutoCompleteV2...