You Asked
Hi Tom,
I'm trying to learn how to use the checkbox on a web form.
What I wan't the package to do is update the record if the checkbox box was checked.
The user may click on 1 or more checkboxes. Such as checkbox 2, 5, 7, etc...these
records will be updated.
If the user does not click on a checkbox
then no records will be updated when the formsubmit is clicked.
I can not get the owa_util.ident_arr array(s) to coordinate. For example, if I
click on the second checkbox, I update the wrong record...
Thanks,
Richard
--here is the code using emp table.
CREATE OR REPLACE package demoUpdate_Checkbox6
as
PROCEDURE sample2_form_emp ;
procedure do_something( p_old_cols in owa_util.ident_arr,
p_old_ename in owa_util.ident_arr,
p_new_ename in owa_util.ident_arr,
p_old_job in owa_util.ident_arr,
p_new_job in owa_util.ident_arr);
end;
/
CREATE OR REPLACE package body demoUpdate_Checkbox6
as
PROCEDURE sample2_form_emp
IS
BEGIN
htp.htmlopen;
htp.bodyopen;
htp.paragraph;
htp.formopen('demoUpdate_Checkbox6.do_something');
htp.tableOpen;
htp.tableRowOpen; -- <TR>
htp.tableHeader ('Check Emp no to Update');
htp.tableHeader ('Emp name');
htp.tableHeader ('Job');
htp.tableRowClose; -- </TR>
-- do we need to initialize the arrays??
htp.formHidden( 'p_old_cols', 'x');
htp.formHidden( 'p_old_ename', 'x');
htp.formHidden( 'p_new_ename', 'x');
htp.formHidden( 'p_old_job', 'x');
htp.formHidden( 'p_new_job', 'x');
-- Is this te correct way to get the records I want?
for x in ( select '</td><td><input type="checkbox" value="'||to_char(empno)||'"name=p_old_cols>'||to_char(empno) empno,
htf.escape_sc(ename) ename,
htf.escape_sc(job) job
from emp
order by empno asc ) loop
htp.p(to_char(x.empno)) ;
htp.p( '</td><td>' );
htp.formHidden( 'p_old_ename', x.ename);
htp.formText( 'p_new_ename', cvalue => x.ename );
htp.p( '</td><td>' );
htp.formHidden( 'p_old_job', x.job);
htp.formText( 'p_new_job', cvalue => x.job );
htp.p( '</td></tr>' );
end loop;
htp.formsubmit(NULL,'Go');
htp.formclose;
htp.bodyclose;
htp.htmlclose;
END;
procedure do_something( p_old_cols in owa_util.ident_arr,
p_old_ename in owa_util.ident_arr,
p_new_ename in owa_util.ident_arr,
p_old_job in owa_util.ident_arr,
p_new_job in owa_util.ident_arr)
is
begin
for col_counter in 2 .. p_old_cols.count LOOP
-- debug ...
htp.bold('emp old# ' ||p_old_cols(col_counter)) ;
htp.br;
htp.bold('ename old ' ||p_old_ename(col_counter)) ;
htp.br;
htp.bold('enane new ' ||p_new_ename(col_counter)) ;
htp.br;
htp.bold('job old ' ||p_old_job(col_counter)) ;
htp.br;
htp.bold('job new ' ||p_new_job(col_counter)) ;
htp.br;
update emp
set ename = upper(p_new_ename(col_counter)),
job = upper(p_new_job(col_counter))
where empno = to_number(p_old_cols(col_counter)) ;
htp.bold( 'update to emp ' || p_old_cols(col_counter)||' Name '||p_new_ename(col_counter) );
if ( sql%rowcount = 0 ) then
htp.bold( ' failed, someone else changed it'||p_new_ename(col_counter) );
else
htp.bold( ' succeeded...' );
end if;
htp.paragraph ;
END LOOP;
EXCEPTION
WHEN no_data_found THEN
htp.paragraph;
htp.line;
htp.p('No data found...') ;
htp.bodyclose;
htp.htmlclose;
end;
end;
/
and Tom said...
that is the way checkboxes work. It is not an OWA issue -- it is the manner in which the web itself "works"
it is the manner in which HTTP encodes the data. The unchecked checkboxes are "not sent", there is no data for them. They quite simply "do not exist"
This is why you don't see many checkboxes on the web in general.
I prefer to use a drop down list with two elements myself. Sort of a "yes", "no" toggle. In that fashion, each "row" in the form would have a Y or N value.
Alternatively, you could have the checkboxes be "subscripts", like this:
....
L_CNT := 1;
for x in ( select '</td><td><input type="checkbox"
value="'||L_CNT||'"name=p_old_cols>'||to_char(empno) empno,
htf.escape_sc(ename) ename,
htf.escape_sc(job) job
from emp
order by empno asc ) loop
htp.p(to_char(x.empno)) ;
htp.p( '</td><td>' );
htp.formHidden( 'p_old_ename', x.ename);
htp.formText( 'p_new_ename', cvalue => x.ename );
htp.p( '</td><td>' );
htp.formHidden( 'p_old_job', x.job);
htp.formText( 'p_new_job', cvalue => x.job );
htp.p( '</td></tr>' );
end loop;
Now, in your update routine, your array from the check box would be subscripts into the other array. That is, if someone clicked on rows 1, 3, 5 and 7 -- you would get a checkbox array with the values 1, 3, 5 and 7 in it -- with which you can subscript the p_old_ename and p_new_ename array.
Actually -- truth be told -- I would hate an interface that didn't "recognize" that I changed something. Why should I have to type over someones ENAME and click a little box to tell you "please update this row". I should only have to type over the ENAME field -- that should be sufficient data for you (the programmer) to figure out what I the end user want done -- update this guys ename!
Rating
(2 ratings)
Is this answer out of date? If it is, please let us know via a Comment