0 Replies Latest reply on Mar 7, 2011 10:21 AM by wesley.pcds

    Problem accessing dynamically created div

    wesley.pcds

      I have a problem accessing a div that was created as part of an innerHTML call. When running in a browser it works fine, but running in AIR I get a null value returned. Is there a way to add these elements into the DOM when they are loaded from an external file?

       

      function loadPage(refDiv, toLoad){

      getPage = new XMLHttpRequest();

      getPage.open("GET", "/lib/html/"+toLoad, true);

      getPage.onreadystatechange = function(){

      if (getPage.readyState == 4) {

      document.getElementById(refDiv).innerHTML = getPage.responseText;

      pageHandler(toLoad);

      }

      }

      getPage.send();

      }

       

      function viewTasks(){

      loadPage('app_body','viewTasks.html');

      getTasks();

      }

       

      function loadTask(rowid,taskArray){

      var taskRow = '<tr>'+

        '<td>'+taskArray.date_scheduled+'</td>'+

      '<td>'+taskArray.service_requested+'</td>'+

      '<td>'+taskArray.service_status+'</td>'+

      '<td>'+taskArray.tech_id+'</td>'+

      '<td>Update Status | Edit Task</td>'+

        '</tr>'

       

      // This is where it stops. Comes back with task_list_row being null

      document.getElementById('task_list_row').innerHTML += taskRow;

      }

       

      //Read all tasks in the local DB and fill the task list

      function getTasks(){

      SQLQuery.text = 'SELECT * FROM loc_task_data';

      try{

      SQLQuery.execute();

      } catch(error){

      air.trace('Data could not be retrieved from the loc_task_data');

      }

      var returnTasks = SQLQuery.getResult().data;

      for(i=0;i<returnTasks.length;i++){

      loadTask(i,returnTasks[i]);

      }

      }

       

       

      //Contents of viewTasks.html

      <div id="app_wrapper">

        <div id="task_list_wrapper">

      <table>

        <tr>

        <th>Scheduled Date</th>

        <th>Task</th>

        <th>Status</th>

        <th>Technician</th>

        <th>Controls</th>

        </tr>

        <div id="task_list_row"></div>

      </table>

        </div>

      </div>