Himanshu
Himanshu

Reputation: 825

Trouble accessing a XUL element from JavaScript

I am having problem to access an element in my file.xul using DOM methods as given below if I do it inside the function someone.listen_request().

But it works fine if I do it inside the progress_bar() function.

Can anyone help me in this case.

My code:

// Listening to an event from a php/html file
var someone = 
{
  listen_request: function() 
  {
    document.addEventListener("record-id", function(event) 
    {
      var node = event.target, doc = node.ownerDocument;
      var d=node.getUserData("data");
      var str=d.split(",");
      var text=str[0];
      var record_id=str[1];
      var field_id=str[2];// Working fine till here
      // **this is not working**
      document.getElementById("Telephone2").value="helo"; 
    }, false, true);
  }
}

someone.listen_request();

// Called at onLoad and onBlur..
function progress_bar(len,page_values)
{
  // **here it is working fine**
  document.getElementById("Telephone2").value="helo";
  var filed_cnt=0;
  var tot_rows=0;
  for(i=0;i<len;i++)
  {
    if(page_values[i]!="")
    { 
      filed_cnt+=parseInt(1);
    }
  }
  var compeletion= (filed_cnt/len)*100;
  var complete=Math.round(compeletion);
  document.getElementById("pbar").value=complete;
  document.getElementById("meter").value=complete;
}

Upvotes: 0

Views: 351

Answers (1)

Himanshu
Himanshu

Reputation: 825

Finally I did it..

The code below works for me :

mainWindow.document.getElementById("sidebar").contentDocument.getElementById("Telephone2").value="hello";

Upvotes: 1

Related Questions