This discussion is archived
6 Replies Latest reply: Mar 8, 2013 8:45 PM by Siberia RSS

Help with anonymus pl/sql layout using javascript

Siberia Newbie
Currently Being Moderated
Hi people.

i want to display some records on a region (using apex 4.2) , this anonymous pl/sql script below shows 3 records from database, but the layout only shows me the first record with it's data, the others 2 records, only show me labels.
i have verified this same query creating a report and it shows the 3 records correctly.
i guess i am doing something wrong with this javascript routine or i am surely missing something,
in this link you can see the layout i am getting. (http://sdrv.ms/Xrv0J8).

the other little help i need is to display in one row for each record. actually i am getting one row for each label and one row for each data record. i have read and found is something about /div, but i don't no how to change it to get desired results, any suggestion is welcome.

thanks in advance for any help.



i am completely new in apex and java script, but i have several years experience in pl/sql.

-------


The Script :

Begin
Declare
Cursor Deliv Is
Select item,
To_char (Delivery, 'month dd, yyyy hh24:mi:ss') Delivery,
Current_date
From pending_items;
Begin
For A In Deliv Loop
Begin
Sys.Htp.P ('<script type="text/javascript">');
Sys.Htp.P ('function cdtd() {');
Sys.Htp.P (' var xmas = new Date("' || a.delivery || '")');
Sys.Htp.P (' var now = new Date();');
Sys.Htp.P (' var timeDiff = xmas.getTime() - now.getTime();');
Sys.Htp.P (' if (timeDiff <= 0) {');
Sys.Htp.P (' clearTimeout(timer);');
-- Sys.Htp.P (' document.write("Some Text Here!");');
Sys.Htp.P (' // Run any code needed for countdown completion here');
Sys.Htp.P (' }');
Sys.Htp.P (' var seconds = Math.floor(timeDiff / 1000);');
Sys.Htp.P (' var minutes = Math.floor(seconds / 60);');
Sys.Htp.P (' var hours = Math.floor(minutes / 60);');
Sys.Htp.P (' var days = Math.floor(hours / 24);');
Sys.Htp.P (' hours %= 24;');
Sys.Htp.P (' minutes %= 60;');
Sys.Htp.P (' seconds %= 60;');
Sys.Htp.P (' document.getElementById("daysBox").innerHTML = days;');
Sys.Htp.P (' document.getElementById("hoursBox").innerHTML = hours;');
Sys.Htp.P (' document.getElementById("minsBox").innerHTML = minutes;');
Sys.Htp.P (' document.getElementById("secsBox").innerHTML = seconds;');
Sys.Htp.P (' var timer = setTimeout("cdtd()",1000);');
Sys.Htp.P ('}');
Sys.Htp.P ('</script>');
Sys.Htp.P ('Days ');
Sys.Htp.P ('<div id="daysBox"></div>');
Sys.Htp.P ('Hours');
Sys.Htp.P ('<div id="hoursBox"></div>');
Sys.Htp.P ('Minutes');
Sys.Htp.P ('<div id="minsBox"></div>');
Sys.Htp.P ('Seconds');
Sys.Htp.P ('<div id="secsBox"></div>');
Sys.Htp.P ('<script type="text/javascript">');
Sys.Htp.P ('cdtd();</script>');
End;
End Loop;
End;
End;
  • 1. Re: Help with anonymus pl/sql layout using javascript
    Tom Petrus Expert
    Currently Being Moderated
    Why? Why are you doing it this way?
    Why are you not using a standard report, and leverage your sql/plsql skills to get the output you desire?
    Why would you output a fully standalone javascript procedure through plsql/htp.p calls?

    What are you trying to achieve and why did you choose this path?
  • 2. Re: Help with anonymus pl/sql layout using javascript
    fac586 Guru
    Currently Being Moderated
    Tom wrote:
    Why? Why are you doing it this way?
    Why are you not using a standard report, and leverage your sql/plsql skills to get the output you desire?
    Why would you output a fully standalone javascript procedure through plsql/htp.p calls?

    What are you trying to achieve and why did you choose this path?
    You beat me to it ;-) . Bizarre.
  • 3. Re: Help with anonymus pl/sql layout using javascript
    Tom Petrus Expert
    Currently Being Moderated
    Must be rubbing off on me! This question reminded me of an answer you gave recently, referring to the XY-problem. That stuck with me!
  • 4. Re: Help with anonymus pl/sql layout using javascript
    Siberia Newbie
    Currently Being Moderated
    Hi Tom.
    i am doing this because i want to show some gif (animated files) files according to the date of delivery. besides i want the user see the remining live time for an order delivery . actually i did it with a report as you said, but i think with this javascript i will get a better GUI.
    thanks
  • 5. Re: Help with anonymus pl/sql layout using javascript
    Tom Petrus Expert
    Currently Being Moderated
    Let's focus on your delivery dates and javascript for now.
    Why you would put your javascript in htp.p calls in a plsql region is quite beyond me. When you edit the page there is a javascript region where you can put global variables and functions, an excellent spot for this then, and a lot more maintainable than this.
    Now it's also obvious that your query on pending items will return more than one record. So, using a report would serve you well in this case. However, using code like this:
    document.getElementById("daysBox").innerHTML = days;
    document.getElementById("hoursBox").innerHTML = hours;
    document.getElementById("minsBox").innerHTML = minutes;
    document.getElementById("secsBox").innerHTML = seconds;
    will not serve you. getElementById is meant to return one element uniquely identified by an ID. If you have a report with multiple rows, and elements on each row with the same ID, you are doing something wrong. You would need the delivery date per row, and I guess that you put out your code with htp.p because you do not know how to deal with that and passing it in to the javascript procedure.
    But wouldn't it be more oppurtune for you to simply create a report with a source sql where you calculate each part of the date, and then refresh this region with a certain interval. If you'd refresh every 5 minutes, wouldn't that be more than fast enough to keep track of things? Don't forget, refreshing a region will execute the sql again.
    It's not that you can't accomplish a multirecord report with a countdown per row, but are you comfortable enough with javascript and jquery to code and maintain that versus leveraging plsql and dynamic actions (there is even a dynamic action timer plugin provided by oracle)?
  • 6. Re: Help with anonymus pl/sql layout using javascript
    Siberia Newbie
    Currently Being Moderated
    Thanks TOM, you are really good.
    this is the answer i was looking for,
    thanks again !

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points