Sunday, July 29, 2007

Oracle APEX: onload in Page HTML Body Attribute

Did you already try to put an onload javascript event in the HTML body of your page in APEX?

You may want to do that to run some initial javascript when your page loads.
For ex. in DG Tournament I use the onload event to enable Google Suggest.

In Oracle Application Express you put the onload event in the HTML Body Attribute section


If you would look in the source of your HTML page you would see something like:

<body onload="get_ApexEvangelists();">

However, when you try to put the above code as HTML Body Attribute, you may get the error "You may not declaratively set cursor focus if you specify an ONLOAD in this attribute."
The complete message:
You should always read the messages ;-) But I noticed (also with myself) that you check quickly your code to see what you did wrong. However it has nothing to do with your code...

You can fix this error by go to the Display Attributes of your Page and set the Cursor Focus to "Do not focus cursor" instead of that APEX puts the focus to the first item of the page.

People seeing this message by "Googling" the error, didn't read neither ;-)

6 comments:

Jornica said...

Dimitri,
If you do not want to change the cursor focus, then you can call the addLoadEvent i.e. addLoadEvent(get_ApexEvangelists) in the HTML Footer text ( see
APEX Javascript Documentation). This approach adds a function to any previous specified onload functions instead of overwriting the previous specified ones.

With kind regards,

Jornica

Dimitri Gielis said...

Hi Jornica,

Yes, that's a great addition to my post.

You have different possibilities to come to the same result, you can even put the javascript call in the footer text.

Thanks,
Dimitri

Wei said...

I want to implement the exact effect like your app. Could you give me some suggestion? Thanks so much!
http://forums.oracle.com/forums/thread.jspa?threadID=942353&tstart=0

Anonymous said...

another alternative to set the cursor:
1. disable cursor focus
2. html body attribute -
ONLOAD = "first_field('Px_item_name');"

Unknown said...

Hi All
I like to login to my Apex application from a link provided in a different website.User name need to be verified.
Any suggestions?

Thanks
CD

Tokke said...

Hi All...

Is there any way that you could indicate where the equivalent of the HTML body attribute is to be found within APEX 5.0.

Where specifically can I find a "Page HTML Body Attribute" within APEX 5.0?

I am reading up on incorporating JavaScript within APEX 5.0, which to my mind is different compared to APEX 4.1.
Alternatively, could somebody please indicate the location of instructions on how to use JavaScript in APEX 5.0, which could be compared to https://docs.oracle.com/cd/E14373_01/appdev.32/e13363/javascript.htm#HTMAD009.

Any help is much appreciated.