 |
|
APEX: Managing APEX JavaScript Source Code
Oracle Tips by Burleson Consulting |
Managing APEX JavaScript
Source Code
Although JavaScript can be embedded almost
anywhere within the HTML source code it is most commonly embedded
between the <head> and </head> tags. In HTML DB this area is
identified in each application page in the HTML Header region of the
Page Attributes page.
Embedding JavaScript "See
JavaScript" source code in HTML DB can be accomplished in
any of 3 ways:
-
§
As In-Line source code in the HTML Header section of
the page attributes for an application page.
-
§
As a Static File in Shared Components -> Static Files.
-
§
As a file in a directory on the machine hosting the
HTTP Server.
By this point in the book you are familiar with
creating the various objects so I won’t walk you through it. To
exercise the steps in this section you should create a new
application with a region including two page items: 1) a USERNAME
page item of type Text Field; 2) a PASSWORD page item of type
Password (don’t use the Password (submits when Enter pressed)
option). Also create a button with the name SUBMIT in the region as
Create a button in a region position.
The JavaScript we will be using in this section
is shown in listing x.1 and is available in the on-line code depot
so you don’t have to type it yourself.
SEE
CODE DEPOT FOR FULL SCRIPTS
<script
language="JavaScript1.1" type="text/javascript">
function
setFocus(PageItem) {
document.getElementById(PageItem).focus();
}
function validateLogin()
{
if (document.getElementById('P4_USERNAME').value
== "") {
alert("Login ID
must have a value provided.");
document.getElementById('P4_USERNAME').focus();
}
else if (document.getElementById('P4_PASSWORD').value
== "") {
alert("Password
must have a value provided.");
document.getElementById('P4_PASSWORD').focus();
document.getElementById('P4_PASSWORD').select();
}
else {
doSubmit('SUBMIT');
}
}
</script>
<
Listing x.1 – JavaScript sample.
SEE
CODE DEPOT FOR FULL SCRIPTS
The code in Listing x.1 performs
two functions. One is to set the focus of the page item and the
other is to validate the username and password page items are not
null before the page is submitted for processing.
The button you created is going to
be used to execute the validateLogin function. If the validation is
ok the function will then perform the SUBMIT for the page.
For more information on this topic, see the
book "Easy Oracle HTML-DB Application Express
", the best book anywhere on expert APEX
development:
APEX developer support:
 |
For APEX development support just call to gat an
Oracle Certified professional for all APEX development
projects. |
 |
Easy Oracle HTML-DB Application Express
By Michael Cunningham & Kent Crotty
Only $27.95
Buy it now and get the code depot download
|
|