Saturday, April 13, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  160] [ 3]  / answers: 1 / hits: 25588  / 9 Years ago, mon, december 14, 2015, 12:00:00

Is it possible to have JavaScript code in the PL/SQL block.
I want to execute the pl/sql block containing JavaScript code on submit in oracle Apex page process.



DECLARE
v_count NUMBER;

BEGIN
select count(*) into v_count
from summary
where prd_items = 'Total';

HTP.p ('<script type=text/javascript>');
HTP.p ( 'alert(''The value of Total for BU is ' ||v_count|| '.n'
|| 'You have to enter correct values to proceed further n'');');
HTP.p ('</script>');
END;


I have Submit button in my page region and this pl/sql block is page processing item and execute on page submit(Conditional:Submit).



But I am not able to pop-up the alert box. Please advise.



Thank you.


More From » oracle

 Answers
19

Is it possible to have JavaScript code in the PL/SQL block?





  • YES



But, what you're trying to do wont work which is passing javascript function AFTER SUBMIT.It'll only work if you change the point of execution to AFTER HEADER.



Alternatively, if you just want to validate the values entered and doesn't want to use apex validation, you can use APEX_ERROR package.Try this.



DECLARE
v_count NUMBER;

BEGIN
select prd_items into v_count
from summary
where prd_items = 'Total';
-- I dont really know what you want to
--accomplish with this query but Im pretty sure
--It will not return a number
-- if you want to count the number of prd_items it should be like this
--select COUNT(*)
--into v_count
--from summary
--where prd_items = 'Total';


APEX_ERROR.ADD_ERROR(
p_message => 'The value of Total for BU is '||v_count||'.<br>'||
'You have to enter correct values to proceed further',
p_display_location => apex_error.c_inline_in_notification
);

END;


EDIT: if you want to show the error if count not equal to 100 then do something like this:



DECLARE
v_count NUMBER;

BEGIN

Select COUNT(*)
into v_count
from summary
where prd_items = 'Total';

IF v_count != 100 THEN
APEX_ERROR.ADD_ERROR(
p_message => 'The value of Total for BU is '||v_count||'.<br>'||
'You have to enter correct values to proceed further',
p_display_location => apex_error.c_inline_in_notification
);


END IF;
END;

[#64072] Friday, December 11, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alorac

Total Points: 262
Total Questions: 82
Total Answers: 97

Location: Libya
Member since Mon, Dec 7, 2020
3 Years ago
alorac questions
Sat, Oct 10, 20, 00:00, 4 Years ago
Tue, Sep 22, 20, 00:00, 4 Years ago
Wed, Jul 1, 20, 00:00, 4 Years ago
Wed, Jun 3, 20, 00:00, 4 Years ago
Sun, May 17, 20, 00:00, 4 Years ago
;