1
<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"  onclick="myfunction($('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"  onclick="myfunction($('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"  onclick="myfunction($('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"  onclick="myfunction($('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"  onclick="myfunction($('input[id$=SObject]').val());"/> 
</apex:form> 
<script>
function myfunction(value){
alert(value);
}
</script>  

How can i call attribute values in javascript ?

i am getting error as undefined in alert box .

I want to know call attribute to get that value ?

2
  • myfunction($('c:AutoCompleteV2').attr(targetField)) tried but not working Commented May 18, 2016 at 6:44
  • then provide full details in your question..., you did not mention anywhere need values of c:AutoCompleteV2... Commented May 18, 2016 at 7:07

1 Answer 1

1

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')));

});
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.