ok so i'll do a big refresh:
this is my manifest:
{
"manifest_version": 2,
"name": "OnlineShoppingManager",
"version": "1.0",
"description": "The extension shows you how much you spend on online shopping",
"icons": {
"128": "icon128.png",
"48": "icon48.png",
"16": "icon16.png"
},
"browser_action":{
"default_icon": "icon16.png",
"default_popup": "popup.html"
},
"options_page" : "options.html",
"background":{
"scripts":["eventPage.js"],
"persistent": false
},
"permissions": [
"storage",
"notifications",
"contextMenus"
]
}
my full js:
short explanation: in this part im init an empty array.
$(function(){
var boole=0;
var b=0;
$('#enter').click(function(){
if (boole==0){
$("#enterS").show();
boole=1;
b=1;
}
if(b==1)
{var purchases = [];
chrome.storage.sync.set({purchases:[]});}
else{
$("#enterS").hide();
boole=0;
$('#Amount').val('');
$('#ProductName').val('');
$('#Date').val('');
}
});
}); short explanation:in this part geting the array from the storage, and show this to the user in a table, this goes right ahead, b4 the user do something. and in the other part after the click event, im adding my user new data to the table, and adding it to the 2D array (the form has 4 inputs, each form field is saved as a row in the array)
chrome.storage.sync.get({purchases:[]},function(arr)
{
var purchases=arr.purchases;
var l=purchases.length();
var table = document.getElementById("MyTable");
for(var i=0;i<l;i++)
{
var tr = document.createElement("tr");
for(var j=0;j<4;j++)
{
var txt = document.createTextNode("some value");
var td = document.createElement("td");
td.appendChild(txt);
}
tr.appendChild(td);
table.appendChild(tr);
}
});
$('#submitForm').click(function(){
chrome.storage.sync.get({purchases:[]},function(arr)
{
var row=[$('#ProductName').val(),$('#Amount').val(),$('#Date').val(),$('#WebStore').val()];
var purchases=arr.purchases;
purchases.push(row);
//$('#product').text(purchases[0][3]);
var table = document.getElementById("MyTable");
var tr = document.createElement("tr");
for(var j=0;j<4;j++)
{
var txt = document.createTextNode(purchases[0][j]);
var td = document.createElement("td");
td.appendChild(txt);
tr.appendChild(td);
}
table.appendChild(tr);
chrome.storage.sync.set({purchases:purchases});
});
html relevant part:
<form id="enterS" style="display: none;" method="post" >
<label for="ProductName">Product Name:</label>
<input type="text" id="ProductName">
<label for="Amount">Amount:</label>
<input type="text" id="Amount">
<br>
<label for="Date">Date:</label>
<input type="text" id="Date">
<br>
<label for="WebStore">Which Web?:</label>
<br>
<input type="text" id="WebStore">
<br>
<input type="button" value="Submit" id="submitForm">
<input type="button" value="Reset" id="reset">
</form>
<h3>the product name is..<span id="product">0</span></h3>
<button class="button" id="show" style="vertical-align:middle"><span>Show My Spendings </span></button>
<div id="showInfo" style="display: none;">
<h3>total is:<span id="total">0</span></h3>
<table id=MyTable>
<tr>
<th>Product</th>
<th>Amount</th>
<th>Date</th>
<th>Site</th>
</tr>
</table>
i dont have a background file yet.
so ill try to make my self clearer this time. after some helper said it i understood that the problem is the asynchronous of the set,get functions, so i looked over the answers for this problem (just understanding what was the problem was helpful!) and i understood that i have a lack of knowledge in few things.
and i saw alot of people write in this form (this is an exmple):
function storeUserPrefs() {
var key='myKey', testPrefs = {'val': 10};
chrome.storage.sync.set({key: testPrefs}, function() {console.log('Saved', key, testPrefs);});
}
andi have a problem to understand , he is trying to set testprefs, why should he use the key,and how would i do in my case when i want to an array.
and a stupied question, to see if im starting to understand:my purpose is to "wait" to set func to finsh her work and the continue with the ret of the code? and how the console.log help me to do this?
im sorry im just so confused...
i have great hopes that ill be clearer this time, please help if you can, and forgive my ignorance, and if i didnt write it good this time ill, edit again.
thx!