« What's On the Shelf Right Now? | Main | AutoCad Upgrade »
September 20, 2005
Processing Multiple Row Check Boxes - Part III
If you have followed Part I and Part II of this series, then you know that we are using our Oracle database to display a web page. This particular web page we are studying displays all work requests that are open, one per row, with a checkbox displayed at the end of each record. When a user checks one or more checkboxes and presses the "Close Selected Work Requests" button, a javascript function called closeReqs() loops through all the records and creates a marker array with the value "true" set wherever a checkbox was checked. If there are records to be closed, then this statement is executed:
document.hist.submit();
Here in Part III, we will see what this does.
In order to know what document.hist.submit() does, we must go to the form tag in our procedure named "hist". Here is the tag (with < changed to _ for display purposes):
_FORM action = "plant.plant_admin.close_req" method = "post" name=hist>
You can see that the form tag calls the plant_admin.close_req procedure. Let's see what that procedure looks like:
procedure close_req (reqno List, checker List, marker List)
is
vx varchar2(100);
cursor reqs is
select *
from plant.wrk_requests_data
where status is null;
begin
fmm30.template.header;
htp.print('
_script language=javascript>
var arr = new Array();
function goHome(){
window.navigate('''||ADMIN_URL||''');
}
_/script>
_h2>Record of Closed Work Requests_/h2>
_hr 80%>
');
for i in 1..reqno.count() loop
if(marker(i) = 'true') then
update plant.wrk_requests_dataset status = 'C'
where request_no = reqno(i);
htp.print('
_FORM action = "plant.plant_admin.close_req" method = "post" name=document_detail>
_table>
_tr>_td>This request number has been closed:_/td>_td>'||reqno(i)||'_/td>_/tr>
_/table>
_/FORM>
');
end if;
end loop;
htp.print('
_br>_br>
_input type=button class=button value=" Back to Work Request Admin " onclick="goHome()">
');
commit;
end close_req;
You can see that this procedure begins with a cursor reqs that selects all open work requests from the table. A for loop processes the marker array looking for a value of "true". When such a value is found, then the table is updated where the request_no = reqno(i). This is worth stopping and considering. The web browser does a really neat thing for you when multiple records are displayed on a form. It automatically creates arrays for each of the text box, check box, and hidden objects. All the data for one record can be found at the same index. So, marker[i] and reqno[i] can be matched up to get the request number that needs to be closed. This is very powerful stuff!
From here it's all downhill. The work requests that are closed are displayed as feedback information for the user, and finally there is a button that takes the user back to the main page. The main page will once again display the open work requests, but not the ones that we just closed.
Let's review. Our goal was to create a way for the user to see all open work requests, and then to easily close one or more of them. We displayed a list of open work requests, one to a line, with a checkbox at the end of each line. The user then selected the work requests to close by simply checking the appropriate box or boxes and clicking a button. We then processed the request, making sure that at least one box had been checked, and creating a marker array which held a value of true at the index of the record to be closed. We then looped through the marker index and closed each record at the same index of the "true" marker value.
I hope you can see a way to use this technique to make your application more efficient and more user friendly.
Posted by rossm at September 20, 2005 1:45 PM
Comments
Post a comment
Thanks for signing in, . Now you can comment. (sign out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)