Title: button onclick=&#8221;increment&#8221;
Last modified: March 28, 2022

---

# button onclick=”increment”

 *  Resolved [axbx](https://wordpress.org/support/users/axbx/)
 * (@axbx)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/button-onclickincrement/)
 * Hi !
    In my tablepress, i’d like to add in cell B1, an incrementing button wich
   add 1 at the A1 cell value.
 * In B1 cell, I wrote this in Avanced Editor :
 * <button onclick=”increment()”>+</button>
 * <script>
    var data = 0;
 * function increment() {
    data = data + 1; document.getElementById(“[table-cell
   id=6 cell=A1 /]”).innerText = data; } </script> Something is wrong, because A1
   doesn’t change :). Is it the celle A1 id ? Could somebody help me please ? Sorry
   for my bad English and my bad code also ! Bets regards
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fbutton-onclickincrement%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 15 replies - 1 through 15 (of 29 total)

1 [2](https://wordpress.org/support/topic/button-onclickincrement/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/button-onclickincrement/page/2/?output_format=md)

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15503794)
 * Hi,
 * thanks for your post, and sorry for the trouble.
 * This will not work like that. You are using the Single Cell Shortcode there, 
   which will only retrieve the value of that A1 cell and paste it into your JavaScript
   code. You could maybe add something like
 *     ```
       <span id="data-value" />
       ```
   
 * into cell A1, and then use this JS code:
 *     ```
       document.getElementById( 'data-value' ).innerText = data;
       ```
   
 * Regards,
    Tobias
 *  Thread Starter [axbx](https://wordpress.org/support/users/axbx/)
 * (@axbx)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15505189)
 * Hi, many thanks for your answer.
    I think I begin to understand ! But my problem
   is : if I add <span id= etc /> in cell A1, I get this message !ERROR! A1 does
   not contain a number or expression, and, of course, I can’t use cell A1 into 
   calculs. And I have to use it in calculs
 * Is there a place where I could add this lign <span id= etc .. />.
    In a file 
   of WP-content/plugins/admin perhaps ?
 * Many thanks.
    Best regards
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15505354)
 * Hi,
 * ok, if you want to use the cell A1 in calculations, you’ll indeed not be able
   to use HTML code in it. However, I’m not sure that I understand what you want
   to achieve with that increment button and where… Even if you had such a button,
   this would not update the calculations, so this would not work anyways. Sorry
   for not having better news here.
 * Regards,
    Tobias
 *  Thread Starter [axbx](https://wordpress.org/support/users/axbx/)
 * (@axbx)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15505989)
 * Hi
    Aïe ! I’m making a cooking recipes site. In cell A1, is the number of pers.
   In others cells, the flour, eggs etc, with change with the number in A1, with
   calculations. For exemple, my recipe is given for 5 pers, you need (=A1*400),
   so 200g flour, 5 eggs. I’d like that the user could change the number in A1, 
   with an increment buttom, to get automaticly flour, eggs etc for 6, or 7 or 8..
   pers.
 * All my tables will have the number of pers in cell A1, so I expected I could 
   give it an Id..somewhere in a file, outside the cell.
 * I don’t know if you’ll undersatnd me :), speaking English is difficult for me,
   you can see it !
    Thanks a lot for your answer ! Best regards
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15506561)
 * Hi,
 * yes, I understand! 🙂 Unfortunately, the formula calculation engine in TablePress
   does not support something like this. It can only calculate formulas on the server,
   before the table is sent to the visitor’s browser. It can however not update 
   calculation results when some button is clicked. You will instead need a custom
   JavaScript-based solution. The formulas in TablePress will not be helpful here,
   unfortunately 🙁 Sorry for not having better news.
 * Regards,
    Tobias
 *  Thread Starter [axbx](https://wordpress.org/support/users/axbx/)
 * (@axbx)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15506843)
 * Aïe aïe aïe !
    Lots of thanks, for your answers. Best regards
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15507773)
 * Hi,
 * sure, no problem!
 * Best wishes,
    Tobias
 *  Thread Starter [axbx](https://wordpress.org/support/users/axbx/)
 * (@axbx)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15509989)
 * Hi,
    I dare contact you again : this following code seems good because it works
   very well in .html. But if I paste it in a cell of my TablePress, it doens’t 
   work. Would you know why ? (We see the number 5, the 3 buttons +, raz, -, we 
   can click on their but nothing else happens.)
 * Many thanks,
    Regards
 * <div id=”data-value”>5</div>
    <button onclick=”increment()”>+</button> <button
   onclick=”reset()”>raz</button> <button onclick=”decrement()”>-</button> <script
   >
 * var data=5;
 * function increment() {
    data = data + 1; document.getElementById(“data-value”).
   innerText = data; }
 *  function decrement() {
    data = data – 1; document.getElementById(“data-value”).
   innerText = data; }
 *  function reset() {
    data = 5; document.getElementById(“data-value”).innerText
   = data; } </script>`
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15510074)
 * Hi,
 * most likely, it’s the line breaks that cause trouble here (these are automatically
   converted to HTML `<br>` tags).
    I therefore recommend to put the part from `
   <script`> to `</script>` outside of the table (into an HTML block before the 
   Shortcode block).
 * Regards,
    Tobias
 *  Thread Starter [axbx](https://wordpress.org/support/users/axbx/)
 * (@axbx)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15510223)
 * Wa ! it works !!
 * So, I’ll persist and try to integer this id”data-value” in calculs formulas, 
   to go on my project, because TablePress is a good plugin and I can’t leave it
   easy !
 * Many many thanks !
    Best regards
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15510312)
 * Hi,
 * great! That’s good to hear 🙂
 * Best wishes,
    Tobias
 *  Thread Starter [axbx](https://wordpress.org/support/users/axbx/)
 * (@axbx)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15510941)
 * Hi,
    In cell A1 content is <div id=”pers”/>8 and, if, in A2, I enter =STXT(A1;17;2),
   it’s genial because A2 content is 8 and I can use it in calcul formulas.
 * But, it seems STXT function is not supported by Tablepress.
    Do you know, please,
   if an extension exists witch does it ? Premium TablePresse doest it ?
 * As you can see, I work hard to keep tablePress -:) -:)
    Best regards
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15511612)
 * Hi,
 * sorry, this will not work either 🙁 TablePress does not currently support Excel
   functions that work with text. (Some support for this will come in TablePress
   2.0, soon.)
 * Instead, maybe do it the other way around:
 *     ```
       8   |    =<div id=”pers”>{A1}</div>
       ```
   
 * Regards,
    Tobias
 *  Thread Starter [axbx](https://wordpress.org/support/users/axbx/)
 * (@axbx)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15513269)
 * Hi,
    doesn’t work ! always “!error! A1 does not contain a number or expression”.
   So I’ll wait the next update.:) However, I thank you for your answers (I just
   made a donate).
 * But I wonder : each Cell has a Name, which is well recognize in formulas calcul.
   
   Using a “document.getElementByName().innerText = data” would avoid writting an
   id inside the cell, and would avoid text in it. No ?
 * I tried many things for a name like (cell A1) or cell {A1}, but nothing matches:).
   
   Best regards
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/button-onclickincrement/#post-15513714)
 * Hi,
 * thanks for your donation, I really appreciate it!
 * Using `getElementByName()` will also not help here, sorry. It’s correct that 
   a table cell has a “name”, but this a completely different name and scheme than
   what this function (which is JavaScript code) requires. In principle, it’s possible
   to go without the ID fields, but that also won’t help you. Even if you update
   the cell value, the formulas will not be recalculated or updated. You must do
   all calculations in JavaScript here, the TablePress formulas will not help.
    
   Sorry for not having better news.
 * Regards,
    Tobias

Viewing 15 replies - 1 through 15 (of 29 total)

1 [2](https://wordpress.org/support/topic/button-onclickincrement/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/button-onclickincrement/page/2/?output_format=md)

The topic ‘button onclick=”increment”’ is closed to new replies.

 * ![](https://ps.w.org/tablepress/assets/icon.svg?rev=3192944)
 * [TablePress - Tables in WordPress made easy](https://wordpress.org/plugins/tablepress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tablepress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tablepress/)
 * [Active Topics](https://wordpress.org/support/plugin/tablepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tablepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tablepress/reviews/)

 * 29 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [3 years, 10 months ago](https://wordpress.org/support/topic/button-onclickincrement/page/2/#post-15860971)
 * Status: resolved