Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Calling PL/SQL function from JavaScript
On 27 Aug 2001 14:55:47 -0700, teresni_at_ucia.gov (Terri I.) wrote:
>Is it possible to call a PL/SQL function from within a block of
>JavaScript code? I have a form with a button - clicking that button
>launches some JavaScript code. I would then like that code to run a
>PL/SQL function, but simply including a line within the JS code like
>'var retcode = Function(variable);' results in an error that Function
>is not defined.... Any help would be appreciated!
At first glance, it looks impossible. But recently I got the idea of doing something similar (only with a stored procedure rather than a function). So let's walk through the thought process.
Netscape had some kind of database access from Javascript called 'Livewire' but I don't know if that still exists. Doubtful that would work very well, especially considering that many or most browsers running Javascript would be Internet Explorer.
With PL/SQL Server Pages (PSP), you can mix PL/SQL and Javascript in the same file. But I think the flow of execution would not be what you want. The PL/SQL function would get executed once, as the HTML was generated, rather than each time the event was received by Javascript.
I think we're getting warmer... although kludges of the highest order might lie ahead.
If you used a PSP, or a PL/SQL stored procedure with the PL/SQL Web Toolkit, you could create a window that displayed the function results as part of the HTML. You could open the pop-up window using the URL of the stored procedure, and encode the parameter variable in the URL like so:
popurl = "http://wherever/pls/mypopup?param=" + variable
If this pop-up window contained Javascript, it could assign the value of the PL/SQL function to a Javascript variable, something like:
htp.p('var retcode = ' || Function(param) || ';'
The HTML would contain the actual literal value of the return code. Then the Javascript in the pop-up window could pass the value back to the original window using the notation for calling functions across windows. Then the pop-up window could close itself. (Maybe it was only very tiny to begin with.)
Using the extra window seems like a complete kludge, but I don't see any way to do what you ask without passing the parameters to PL/SQL via name-value pairs in the query string, and passing the return value back as a literal in the HTML code. Maybe instead of a second window, you could use two frames within the same window and set <framename>.location to the URL with the encoded parameter.
John
-- Got an Oracle database question? Try the search engine for the database docs at: http://tahiti.oracle.com/Received on Tue Aug 28 2001 - 19:11:04 CDT