How to increment counter value inside an onClick event? The Next CEO of Stack OverflowHow can I get query string values in JavaScript?How to get the value from the GET parameters?How can I add a key/value pair to a JavaScript object?How to remove item from array by value?How to access the correct `this` inside a callback?React js onClick can't pass value to methodReturn value from javascript onclick to variable or change global variable with onclickOnclick button that add random value from array in textarea no refreshJavascript function counter add up despite declaring new var every timeButton onclick event change all the select option selection in a row
Is a distribution that is normal, but highly skewed considered Gaussian?
Is the D&D universe the same as the Forgotten Realms universe?
Why does standard notation not preserve intervals (visually)
What steps are necessary to read a Modern SSD in Medieval Europe?
Why didn't Khan get resurrected in the Genesis Explosion?
Won the lottery - how do I keep the money?
Where do students learn to solve polynomial equations these days?
INSERT to a table from a database to other (same SQL Server) using Dynamic SQL
What was the first Unix version to run on a microcomputer?
Flying from Cape Town to England and return to another province
Why isn't the Mueller report being released completely and unredacted?
Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?
Do I need to write [sic] when a number is less than 10 but isn't written out?
How do I align (1) and (2)?
0 rank tensor vs 1D vector
Proper way to express "He disappeared them"
Method for adding error messages to a dictionary given a key
A Man With a Stainless Steel Endoskeleton (like The Terminator) Fighting Cloaked Aliens Only He Can See
Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?
How to count occurrences of text in a file?
Why isn't acceleration always zero whenever velocity is zero, such as the moment a ball bounces off a wall?
Can a Bladesinger Wizard use Bladesong with a Hand Crossbow?
Why did CATV standarize in 75 ohms and everyone else in 50?
Is it convenient to ask the journal's editor for two additional days to complete a review?
How to increment counter value inside an onClick event?
The Next CEO of Stack OverflowHow can I get query string values in JavaScript?How to get the value from the GET parameters?How can I add a key/value pair to a JavaScript object?How to remove item from array by value?How to access the correct `this` inside a callback?React js onClick can't pass value to methodReturn value from javascript onclick to variable or change global variable with onclickOnclick button that add random value from array in textarea no refreshJavascript function counter add up despite declaring new var every timeButton onclick event change all the select option selection in a row
I'm quite new to Google App Maker and programming in general, I'm making an app where when a "+" button is clicked (onClick event) fields are added (kinda like a new row in a table with every click). I'm trying to make a counter to keep track of how many "rows" are being created. The thing is that since in App Maker all the code apparently has to be made inside the onClick event, i can't set a global variable and every time the button is clicked the counter restarts, therefore always being 1.
I tried with localStorage but i don't exactly know how to make it work, since it still will always save the same value. How can i fix this?
var count = 0;
count = count +1;
localStorage.setItem('counter', JSON.stringify(parseFloat(count)));
textArea.className = 'app-TextArea';
textArea.style.margin = '8px';
textArea.setAttribute("placeholder", "Follow up # " + localStorage.getItem('counter');
widget.root.descendants.Panel1.getElement().appendChild(textArea);
javascript counter google-app-maker
add a comment |
I'm quite new to Google App Maker and programming in general, I'm making an app where when a "+" button is clicked (onClick event) fields are added (kinda like a new row in a table with every click). I'm trying to make a counter to keep track of how many "rows" are being created. The thing is that since in App Maker all the code apparently has to be made inside the onClick event, i can't set a global variable and every time the button is clicked the counter restarts, therefore always being 1.
I tried with localStorage but i don't exactly know how to make it work, since it still will always save the same value. How can i fix this?
var count = 0;
count = count +1;
localStorage.setItem('counter', JSON.stringify(parseFloat(count)));
textArea.className = 'app-TextArea';
textArea.style.margin = '8px';
textArea.setAttribute("placeholder", "Follow up # " + localStorage.getItem('counter');
widget.root.descendants.Panel1.getElement().appendChild(textArea);
javascript counter google-app-maker
1
If this is an onClick event can you post the surrounding code please.
– James
Mar 21 at 17:31
That's the thing, in App Maker it doesn't seem like i can add surrounding code. It just gives the option to add an onClick event and add the code there, hence i cant initialize "count" outside the onClick event.
– J. IT
Mar 21 at 17:36
add a comment |
I'm quite new to Google App Maker and programming in general, I'm making an app where when a "+" button is clicked (onClick event) fields are added (kinda like a new row in a table with every click). I'm trying to make a counter to keep track of how many "rows" are being created. The thing is that since in App Maker all the code apparently has to be made inside the onClick event, i can't set a global variable and every time the button is clicked the counter restarts, therefore always being 1.
I tried with localStorage but i don't exactly know how to make it work, since it still will always save the same value. How can i fix this?
var count = 0;
count = count +1;
localStorage.setItem('counter', JSON.stringify(parseFloat(count)));
textArea.className = 'app-TextArea';
textArea.style.margin = '8px';
textArea.setAttribute("placeholder", "Follow up # " + localStorage.getItem('counter');
widget.root.descendants.Panel1.getElement().appendChild(textArea);
javascript counter google-app-maker
I'm quite new to Google App Maker and programming in general, I'm making an app where when a "+" button is clicked (onClick event) fields are added (kinda like a new row in a table with every click). I'm trying to make a counter to keep track of how many "rows" are being created. The thing is that since in App Maker all the code apparently has to be made inside the onClick event, i can't set a global variable and every time the button is clicked the counter restarts, therefore always being 1.
I tried with localStorage but i don't exactly know how to make it work, since it still will always save the same value. How can i fix this?
var count = 0;
count = count +1;
localStorage.setItem('counter', JSON.stringify(parseFloat(count)));
textArea.className = 'app-TextArea';
textArea.style.margin = '8px';
textArea.setAttribute("placeholder", "Follow up # " + localStorage.getItem('counter');
widget.root.descendants.Panel1.getElement().appendChild(textArea);
javascript counter google-app-maker
javascript counter google-app-maker
asked Mar 21 at 17:25
J. ITJ. IT
52
52
1
If this is an onClick event can you post the surrounding code please.
– James
Mar 21 at 17:31
That's the thing, in App Maker it doesn't seem like i can add surrounding code. It just gives the option to add an onClick event and add the code there, hence i cant initialize "count" outside the onClick event.
– J. IT
Mar 21 at 17:36
add a comment |
1
If this is an onClick event can you post the surrounding code please.
– James
Mar 21 at 17:31
That's the thing, in App Maker it doesn't seem like i can add surrounding code. It just gives the option to add an onClick event and add the code there, hence i cant initialize "count" outside the onClick event.
– J. IT
Mar 21 at 17:36
1
1
If this is an onClick event can you post the surrounding code please.
– James
Mar 21 at 17:31
If this is an onClick event can you post the surrounding code please.
– James
Mar 21 at 17:31
That's the thing, in App Maker it doesn't seem like i can add surrounding code. It just gives the option to add an onClick event and add the code there, hence i cant initialize "count" outside the onClick event.
– J. IT
Mar 21 at 17:36
That's the thing, in App Maker it doesn't seem like i can add surrounding code. It just gives the option to add an onClick event and add the code there, hence i cant initialize "count" outside the onClick event.
– J. IT
Mar 21 at 17:36
add a comment |
2 Answers
2
active
oldest
votes
You should get data from localStorage
first, then increment it and finally set the new value the localStorage
.
var count = parseInt(localStorage('counter')) || 0; // Get value from localStorage
count = count + 1;
localStorage.setItem('counter', count); // Set new value to localStorage
textArea.className = 'app-TextArea';
textArea.style.margin = '8px';
textArea.setAttribute("placeholder", "Follow up # " + count); // Use new value
widget.root.descendants.Panel1.getElement().appendChild(textArea);
Thank you! It worked!
– J. IT
Mar 21 at 19:30
add a comment |
You can use the page custom properties.
So in the the page, you can a Number custom property and name it counter.
Then your code should look like this:
var count = widget.root.properties.counter || 0;
count += 1;
widget.root.properties.counter = count;
textArea.className = 'app-TextArea';
textArea.style.margin = '8px';
textArea.setAttribute("placeholder", "Follow up # " + count);
widget.root.descendants.Panel1.getElement().appendChild(textArea);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55286040%2fhow-to-increment-counter-value-inside-an-onclick-event%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should get data from localStorage
first, then increment it and finally set the new value the localStorage
.
var count = parseInt(localStorage('counter')) || 0; // Get value from localStorage
count = count + 1;
localStorage.setItem('counter', count); // Set new value to localStorage
textArea.className = 'app-TextArea';
textArea.style.margin = '8px';
textArea.setAttribute("placeholder", "Follow up # " + count); // Use new value
widget.root.descendants.Panel1.getElement().appendChild(textArea);
Thank you! It worked!
– J. IT
Mar 21 at 19:30
add a comment |
You should get data from localStorage
first, then increment it and finally set the new value the localStorage
.
var count = parseInt(localStorage('counter')) || 0; // Get value from localStorage
count = count + 1;
localStorage.setItem('counter', count); // Set new value to localStorage
textArea.className = 'app-TextArea';
textArea.style.margin = '8px';
textArea.setAttribute("placeholder", "Follow up # " + count); // Use new value
widget.root.descendants.Panel1.getElement().appendChild(textArea);
Thank you! It worked!
– J. IT
Mar 21 at 19:30
add a comment |
You should get data from localStorage
first, then increment it and finally set the new value the localStorage
.
var count = parseInt(localStorage('counter')) || 0; // Get value from localStorage
count = count + 1;
localStorage.setItem('counter', count); // Set new value to localStorage
textArea.className = 'app-TextArea';
textArea.style.margin = '8px';
textArea.setAttribute("placeholder", "Follow up # " + count); // Use new value
widget.root.descendants.Panel1.getElement().appendChild(textArea);
You should get data from localStorage
first, then increment it and finally set the new value the localStorage
.
var count = parseInt(localStorage('counter')) || 0; // Get value from localStorage
count = count + 1;
localStorage.setItem('counter', count); // Set new value to localStorage
textArea.className = 'app-TextArea';
textArea.style.margin = '8px';
textArea.setAttribute("placeholder", "Follow up # " + count); // Use new value
widget.root.descendants.Panel1.getElement().appendChild(textArea);
answered Mar 21 at 18:02
birdbird
1,088620
1,088620
Thank you! It worked!
– J. IT
Mar 21 at 19:30
add a comment |
Thank you! It worked!
– J. IT
Mar 21 at 19:30
Thank you! It worked!
– J. IT
Mar 21 at 19:30
Thank you! It worked!
– J. IT
Mar 21 at 19:30
add a comment |
You can use the page custom properties.
So in the the page, you can a Number custom property and name it counter.
Then your code should look like this:
var count = widget.root.properties.counter || 0;
count += 1;
widget.root.properties.counter = count;
textArea.className = 'app-TextArea';
textArea.style.margin = '8px';
textArea.setAttribute("placeholder", "Follow up # " + count);
widget.root.descendants.Panel1.getElement().appendChild(textArea);
add a comment |
You can use the page custom properties.
So in the the page, you can a Number custom property and name it counter.
Then your code should look like this:
var count = widget.root.properties.counter || 0;
count += 1;
widget.root.properties.counter = count;
textArea.className = 'app-TextArea';
textArea.style.margin = '8px';
textArea.setAttribute("placeholder", "Follow up # " + count);
widget.root.descendants.Panel1.getElement().appendChild(textArea);
add a comment |
You can use the page custom properties.
So in the the page, you can a Number custom property and name it counter.
Then your code should look like this:
var count = widget.root.properties.counter || 0;
count += 1;
widget.root.properties.counter = count;
textArea.className = 'app-TextArea';
textArea.style.margin = '8px';
textArea.setAttribute("placeholder", "Follow up # " + count);
widget.root.descendants.Panel1.getElement().appendChild(textArea);
You can use the page custom properties.
So in the the page, you can a Number custom property and name it counter.
Then your code should look like this:
var count = widget.root.properties.counter || 0;
count += 1;
widget.root.properties.counter = count;
textArea.className = 'app-TextArea';
textArea.style.margin = '8px';
textArea.setAttribute("placeholder", "Follow up # " + count);
widget.root.descendants.Panel1.getElement().appendChild(textArea);
answered Mar 21 at 19:33
MorfinismoMorfinismo
2,5401820
2,5401820
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55286040%2fhow-to-increment-counter-value-inside-an-onclick-event%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
If this is an onClick event can you post the surrounding code please.
– James
Mar 21 at 17:31
That's the thing, in App Maker it doesn't seem like i can add surrounding code. It just gives the option to add an onClick event and add the code there, hence i cant initialize "count" outside the onClick event.
– J. IT
Mar 21 at 17:36