Home » SQL & PL/SQL » SQL & PL/SQL » Calculation Field and JavaScript and PL/SQL (2 threads merged by bb)
Calculation Field and JavaScript and PL/SQL (2 threads merged by bb) [message #361295] Tue, 25 November 2008 15:12 Go to next message
ramtin
Messages: 37
Registered: November 2008
Member
Hi,

I am using PL/SQL to generate HTML Page. I have three fields in one form and when the user fill out this Form, She/he input Field one and field two and then press Tab Key to go to field three. However I have to time field one and field two and show it in field three. Could you please give me some information about how Can I do that?

Thank you in advance.
Re: Calculation Field [message #361300 is a reply to message #361295] Tue, 25 November 2008 16:44 Go to previous messageGo to next message
cmerry
Messages: 109
Registered: November 2005
Location: Idaho
Senior Member
Embed a JavaScript function in your PL/SQL code. Add an onBlur event to elements 1 and 2. If both elements have a value, then set the value for element 3.
Re: Calculation Field [message #361301 is a reply to message #361295] Tue, 25 November 2008 17:09 Go to previous messageGo to next message
ramtin
Messages: 37
Registered: November 2008
Member
Thank you for your reply. Could you please send me a sample code for that

Thank you
Re: Calculation Field [message #361319 is a reply to message #361301] Tue, 25 November 2008 23:12 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
This is NOT a PL/SQL or Oracle question.
Search for "javascript onblur" on Google.

Regards
Michel
JavaScript and PL/SQL [message #361537 is a reply to message #361295] Wed, 26 November 2008 20:30 Go to previous messageGo to next message
ramtin
Messages: 37
Registered: November 2008
Member
Hi,

I am using PL/SQL to generate HTML Page. I have a Form with three fields user wants when fill out this Form, She/he input Field one and field two and then press Tab Key to go to field three. However I have to time field one to field two and show result on field three. I learned that I have to use JavaScript onBlur event but I could not find how I should code that in PL/SQL. Could you please give me some sample code that show how can I use that in my PL/SQL Code? I can create JavaScript Function but I need to know how I can call that Function in PL/SQL code.

Thank you in advance
Re: JavaScript and PL/SQL [message #361555 is a reply to message #361537] Wed, 26 November 2008 23:11 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
As I already said in PM, there is nothing in PL/SQL specific to Javascript, it is only text in the page like any other text.
So you have to search for a javascript forum to give you the code.
You didn't call javascript from PL/SQL, the client browser executes the javascript code on event.
This has no more relation with PL/SQL nor Oracle, so the topic is closed.

Regards
Michel
Re: JavaScript and PL/SQL [message #361584 is a reply to message #361555] Thu, 27 November 2008 01:33 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Since the onblur is a property of the textitem, which is/can/might be generated using htp-package (htp.formtext), this actually is or might be PL/SQL-related.
Unlocked the topic.
Re: JavaScript and PL/SQL [message #361594 is a reply to message #361584] Thu, 27 November 2008 02:23 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
In this case, it seems to be more a Forms question, moving it.

Regards
Michel
Re: JavaScript and PL/SQL [message #361705 is a reply to message #361594] Thu, 27 November 2008 11:24 Go to previous messageGo to next message
ramtin
Messages: 37
Registered: November 2008
Member
Hi,


I put one onBlur event on second field and create a function which now just has one alert command. Everything is working fine. Now I need pass two number values to this function and also get back the result of that. Could you please tell me how I can pass two number values which are not part of form and also how I can set function to return back the result of calculation?

Thank you
Re: JavaScript and PL/SQL [message #361743 is a reply to message #361705] Thu, 27 November 2008 19:32 Go to previous messageGo to next message
djmartin
Messages: 10180
Registered: March 2005
Location: Canberra ACT Australia
Senior Member
Account Moderator
For me it is an 'htf/htp' question and should be in 'SQL and PL/SQL'.

I thought you would leave Java out of it and just use
select nvl(itema,0)+nvl(itemb,0)
  into itemc
  from dual;

David
Re: JavaScript and PL/SQL [message #361962 is a reply to message #361743] Fri, 28 November 2008 15:58 Go to previous messageGo to next message
cmerry
Messages: 109
Registered: November 2005
Location: Idaho
Senior Member
Here is a basic example of calling JavaScript from within a PL/SQL procedure.

CREATE OR REPLACE PROCEDURE calc IS
BEGIN
  htp.p
  ('<html>
    <head>
    <title>Calculate Form Values</title>
    <script language="JavaScript">
    function calc() {
      var v1=document.getElementById("val1").value;
      var v2=document.getElementById("val2").value;
      var v3=document.getElementById("val3");
      
      // if both input elements have a value, set the value for
      // the third element to the product of v1 * v2
      if ((v1 != "") && (v2 != "")) { v3.value = v1 * v2; }
    }
    </script>
    </head>
    <body>
    <form>
    <label for"val1">Value 1:</label><input type="text" id="val1" name="val1" size="3" onBlur="calc();"><br />
    <label for"val2">Value 2:</label><input type="text" id="val2" name="val2" size="3" onBlur="calc();"><br />
    <label for"val3">Value 3:</label><input type="text" id="val3" name="val3" size="3">
    </form>
    </body>
    </html>
  ');
END;


And I agree, it is related to PL/SQL not Forms.
Re: JavaScript and PL/SQL [message #362001 is a reply to message #361962] Sat, 29 November 2008 09:06 Go to previous messageGo to next message
ramtin
Messages: 37
Registered: November 2008
Member
Thank you for your reply. I did same as you code in my JavaScript function for test:

function checkInput(){
var field1 = document.PGDETL.f1.value;
var field2 = document.PGDETL.f2.value;
var field3 = document.PGDETL.f3.value;

document.PGDETL.f3.value = document.PGDETL.f2.value;
..
..
.
}

but I will see 'undefined' string in f3 field. Please advice.

Thank You
Re: JavaScript and PL/SQL [message #362002 is a reply to message #362001] Sat, 29 November 2008 09:37 Go to previous message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Post your question in Javascript forum, this is definitively NOT a PL/SQL question.

Regards
Michel
Previous Topic: Query with Timestamp and aggregate Function
Next Topic: SQL Function Convertion Bites to Bytes, KB, MB, GB, TB, PB, EB, ZB, YB
Goto Forum:
  


Current Time: Sat Dec 03 16:01:31 CST 2016

Total time taken to generate the page: 0.06160 seconds