Javascript OnLoad

Hi,

      function setTab(pCurrentTab){
        $('#P6_CUR_TAB').val(pCurrentTab);
      }

      //OnLoad - puts click on Tabs
      $('#ul-PT li a').click(function() {
        setTab(this.id);
      });


// OnLoad -- suppose to click last Tab selected on page load      
      //-------------- Keep track of current tab on submit
      var curTab = '#'+$v('P6_CUR_TAB');
      if( curTab != '#'){
        $(curTab).trigger('click');
        console.log('Trigger['+curTab+']');
      }
      //----


I get the console.log --          Trigger[#a_costBudget_id]

$('#a_costBudget_id').trigger('click'); // when I use this in the console it works..

$('#a_costBudget_id').trigger('click'); // even hard coded this in the onLoad and doesn't work


Any reason this will not work?
Thx, Bill
LVL 2
BILL CarlisleAPEX DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Can we see a full listing - or better a link.
BILL CarlisleAPEX DeveloperAuthor Commented:
sorry propriatary
Tom BeckCommented:
Check the order of events. The click handler needs to be registered before it can be triggered.

Also worth noting here, the jQuery DOM 'ready' event occurs before the jQuery 'load' event. DOM ready would be a better place to put the click handler.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Jessica WhitleySoftware DeveloperCommented:
Are you looking for the $(document). ready event by chance?
Julian HansenCommented:
sorry propriatary
Can you post source?
Prakash SamariyaIT ProfessionalCommented:
If document/web does not loaded completely, it won't work; so we can call that in document's ready event

$( document ).ready(function() {
   // console.log( "ready!" );
  $('#a_costBudget_id').trigger('click'); // even hard coded this in the onLoad and doesn't work

 //Or if it is hyperlink/button simply
 $('#a_costBudget_id').click(); 
});

Open in new window

Julian HansenCommented:
Just for giggles try this
 $('#ul-PT li a').click(function(e) { // ADD e PARAMETER
  e.preventDefault(); // ADD THIS
  setTab(this.id);
});

Open in new window

Without seeing your code we are guessing here - which is not really effective and is going to take a lot more time. If you can post the HTML output from your browser - remove whatever prorprietary info we are not allowed to see and post here - you will get a solution a lot quicker.
Tom BeckCommented:
As I already pointed out, the window 'load' event occurs AFTER the document 'ready' event. You cannot trigger a click event in document 'ready' if you are not registering the click handler until window 'load'. Put the click handler in document 'ready' and the trigger in window 'load'.
BILL CarlisleAPEX DeveloperAuthor Commented:
Hi All,
Thank you for your responses.
I am using Oracle APEX 4.2.6 dev tool..

To be more clear of what I have:

// In Header
<script type="text/javascript">
var htmldb_delete_message='Would you like to perform this delete action?';
function setTab(pCurrentTab){
  $('#P6_CUR_TAB').val(pCurrentTab);
   console.log('Arg '+pCurrentTab);
   console.log('Item '+ $('#P6_CUR_TAB').val());
}
</script>

$(document).ready(function() {
  $('#ul-PT li a').click(function() {
    setTab(this.id);
  });
  /-------------- Keep track of current tab on submit
  var curTab = '#'+$v('P6_CUR_TAB');
  if( curTab != '#'){
    $(curTab).trigger('click');
    //$('#a_costBudget_id').trigger('click');
    console.log('Trigger['+curTab+']');
  }
});

// In Form
<input type="hidden" name="p_t10" id="P6_CUR_TAB" value="">

What could be in the existing code to prevent this from working?
Like sometimes I need to use !important to override the Oracle APEX CSS
Jessica WhitleySoftware DeveloperCommented:
Set the tab as the actively selected tab via the document ready event.  Instead of .trigger use .click.
BILL CarlisleAPEX DeveloperAuthor Commented:
my co-worker took it over..

He is using a cookie

thk u for your help..
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.