0

I need get all inputs of one page with a google extensioin.

My code is executed when charge a page. But I need make a button for this.

If I only write this:

var inputs = document.body.querySelectorAll('input');

The inputs var, content all inputs, fine..

But if I execute a function when push the button dont work.

document.addEventListener('DOMContentLoaded', function () {
    document.getElementById('rellena').addEventListener('click', al);
});
function al(){
  var inputs = document.body.querySelectorAll('input');
  alert("Hello")

}

In this example, the alert are executed fine, but not the querySelectorAll.

After that, I use loop for change the value of inputs. This work without button, but not with button.

PD: If i change alert for a console.log(inputs) don't work. If I put console(inputs )and imput var out of "al" function, this work.

Phyron
  • 613
  • 1
  • 9
  • 25
  • Is the second code fragment in your popup/page-action script? – wOxxOm Sep 22 '15 at 15:42
  • Yes w0xx0m all the code is in popup.js, the button is in default_popup (popup.html). It's posible that querySelectorAll act in page, but if i use the button act in popup of extension? – Phyron Sep 22 '15 at 15:45
  • not a duplicate. the actual error is in the javascript variable scoping of inputs. i cant add an answer because of marked a dup. – Zig Mandel Sep 23 '15 at 13:38
  • @ZigMandel I quote the above: "all the code is in popup.js" – Xan Sep 24 '15 at 21:07
  • I see. so it actually has two bugs. Once moved to the right place, it will have the scoping issue. – Zig Mandel Sep 24 '15 at 21:08

0 Answers0