0

Is it possible to programmatically select a custom button with Jquery, so that when it is selected a Visualforce page is launched? This doesn't seem to be working for me and I'm not getting any errors in the console. It's saying that the button was selected, but the VF page associated with the custom button doesn't launch.

    j$ = jQuery.noConflict();
    j$(document).ready(function(){
    j$("input[name='new_related_case']").on("click", function(e){
            console.log("New Related Case was selected");
     });

    j$(".detailList tr td").each(function(){
       var caseOrgin = j$(this).text();
        if(caseOrgin == "Web"){
            console.log("Case Orgin: Web");
            j$("input[name='new_related_case']").trigger("click");
      }  
  });
});
0

1 Answer 1

1

The each function (as you have it written) only runs when the document is ready.

Try changing it to this (if you want it to run each time the input is clicked:

j$("input[name='new_related_case']").on("click", function(e){
            console.log("New Related Case was selected");
        j$(".detailList tr td").each(function(){
           var caseOrgin = j$(this).text();
             if(caseOrgin == "Web"){
               console.log("Case Orgin: Web");
               //other stuff here                   
         }
     });
10
  • @VanAlfredo By doing that all you did is run the code as the page loads (and possibly break the other click code as the element may not exist as it is ran) so leave the .ready function as it was.....It still will not run the .each function on a click of a button. Did you happen to try what was posted as the answer? You are going to have to modify it a bit to meet your needs as your scope is not entirely clear.
    – Eric
    Sep 6, 2015 at 3:00
  • I see what you mean. I did try the code you provided, but I don't think it's exactly what I'm looking for. I want it so that When caseOrgin is equal to "Web" the browser simulates a user clicking on the custom button, so the associated VF page will launch.
    – VanAlfredo
    Sep 6, 2015 at 3:19
  • @VanAlfredo - It will do what you want with the proper selectors, I cannot say what they should be as your page is not posted....The pattern in the answer should be correct, you will need to figure out the selectors
    – Eric
    Sep 6, 2015 at 3:22
  • I do appreciate your help. I tried using j$(".detailList tr td:contains('Web')") as well, but the j$("input[name='new_related_case']").trigger("click"); still dosen't do anything.
    – VanAlfredo
    Sep 6, 2015 at 3:52
  • are you even getting to that point in the code. does your console.log in the place of the trigger.("click") actually log?
    – Eric
    Sep 6, 2015 at 3:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .