0

Sorry for the little explanation. So i have already done my chrome extension and i already have a save data in my localstorage which is FirstName. so now the getElementById is the one suppose to web scape my current page that i am on to fill up the form when i click START which is button1 Hopefully these clear things

i have also provided my index.html where if i click start it should execute injector.js

index.html

<!DOCTYPE html>
<html>

<head>
 <link rel="stylesheet" href="style.css">
 <style>
  html,
  body {
   height: 200px;
   width: 400px;
  }
 </style>
 
</head>

<body>
 <h1>Adidas ACO</h1>
 <h2>Select your choice</h2>
 <button><a href="./home.html" target="_blank">Go for Setup</a></button>
 
 <button id="buttonstart"><script src="injector.js"></script>
 </script>START</button>
 <!-- <br>
 <br>
 <label for="Title">Title</label>
 <input type="text" id="firstnametitle" name="title" size="50" value=""/> -->


 <!--<script scr="injector.js"></script>-->
 <!--<button onclick="fillforms(fillup)">Start</button>-->
</body>
</html>

injector.js

// Get my button and localstorage data
var button1 = document.getElementById("buttonstart");
var firstName = localStorage.getItem('First Name');
var lastName = localStorage.getItem('Last Name');
var address1 = localStorage.getItem('Address 1');
var address2 = localStorage.getItem('Address 2');
var email = localStorage.getItem('Email');
var phoneNumber = localStorage.getItem('Phone Number');

/// When button is click, it will webscape and fill up 
button1.onclick = function(){
 var firstName = localStorage.getItem('First Name');
 var field1 = document.getElementsByClassName("shippingAddress-firstName");
 fillField(field1, firstName);

 console.log(field1)
 console.log(firstName)
 
}

function fillField(field1, value){
 if(field1){
  field1.value = value;
 }
}

Picture to my console values

1 Answers1

0

Declare the variables firstname and field1 at the start of the file.You have to do it because in your code you can only use those variables inside the button1.onclick function since you have declared them there.

Pratham
  • 11
  • 4
  • But he only uses the variables inside the onclick, no need to make them global. – Reyno Jul 26 '21 at 06:53
  • so basically its a Chrome Extension and it is suppose to fill up the form when i click "Start" which is button1. it is suppose to take my data from my localstorage of the page and fill the form. @Reyno – JustAnotherProgrammer Jul 26 '21 at 08:37
  • You forget to set the class attribute to the input I think. Also why have you have commented some code? – Pratham Jul 29 '21 at 04:02