Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Building select list using Ajax

AlwynJul 20 2009 — edited Jul 20 2009
Hello,

In building a select list using Ajax, I've come across 2 methods set out below.

========
Method 1 - On demand process
========
pl/sql
~~~~~~
:
HTP.PRN('<select>');

FOR r IN (SELECT emp_id, emp_name
          FROM   employees)
LOOP
   HTP.PRN ('<option value="'||r.emp_id ||'">'||r.emp_name||'</option>');

END LOOP;
HTP.PRN('</select>');
:
Javascript
~~~~~~~~~~
:
  if (ajaxReturn) {
      var elemCount = ajaxReturn.getElementsByTagName("option").length;
      
      for(i=0; i<elemCount; i++){
         // do something
       }
   }
:
========
Method 2 - On demand process
========
pl/sql
~~~~~~
:
FOR r IN (SELECT emp_id, emp_name
          FROM employees) 
LOOP
   v_emp_list := v_emp_list||'~rowsep~'||r.emp_id||'~colsep~'||r.emp_name;

END LOOP;

HTP.PRN(v_emp_list);
:
Javascript
~~~~~~~~~~
:
if(ajaxResult) {  
   empSelectObj.options.length = 0;

   var empArray = ajaxResult.split("~rowsep~");

   for(var i=0; i<empArray.length; i++) {
      var colArray = empArray.split("~colsep~");
empSelectObj.options[i] = new Option(colArray[1], colArray[0]);
}
:
Is there any difference in process and performance?  Does the HTP.PRN command send output to the web server immediately?


- Alwyn                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 17 2009
Added on Jul 20 2009
8 comments
704 views