views:

58

answers:

4

So I'm attempting to make a page in Visualforce(salesforce's page creator), and am having issues with the javascript aspect of it. Basically what should happen is that the section will generate a series of links. The javascript needs to click those links. I'm using jquery

<apex:page standardcontroller="Account" extensions="maininvoice">

<apex:repeat value="{!theListOfIDs}" var="anId">
 <apex:outputLink target="_blank" value="{!URLFOR($Page.invoice2,anId)}" styleClass="name" />
</apex:repeat>

<apex:includeScript value="{!URLFOR($Resource.jquery, 'js/jquery-1.4.2.min.js')}"/>
<script type="text/javascript">
 var j$ = jQuery.noConflict();
j$(document).ready(function(){

var anchortags = j$('.name');

            for(i=0;i<=anchortags.length;i++){
                var currentTag=anchortags[i];                        
                    currentTag.trigger(click);
                    alert("your mother");
                    }
            }
            );

</script>

</apex:page>
+2  A: 

Answering your exact question, this: currentTag.trigger(click); should be: currentTag.trigger('click');

But, come on, jQuery can do this all for you in one shot:

$('.name').click();
Jacob Relkin
the thing is, currentTag is going to be a DOM element reference I think, so if he wanted it to work he'd need to write `$(currentTag).trigger('click');` - but he really can avoid the loop altogether because jQuery is happy to do it for him. I guess it's nice however that this incorrect answer is getting you upvotes :)
Pointy
+2  A: 

You're sort-of mixing up jQuery coding with "traditional" coding, and it's not working. Try this:

var anchortags = j$('.name');

anchortags.click();
Pointy
+1  A: 

Something like this:

var j$ = jQuery.noConflict();
j$(function(){
    j$('.name').click();
});

j$(function(){...}); is the same as j$(document).ready(function(){...});

The click() function will be executed for every match in the previous list (j$('.name')). Use of .each(function(){...}); is therefor redundant.

jerone
+1  A: 
var j$ = jQuery.noConflict();
j$(document).ready(function(){
   j$('.name').each(funtion() {
       j$(this).trigger('click');
   });
Ninja Dude