• Resolved axbx

    (@axbx)


    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 to see the link]

Viewing 15 replies - 1 through 15 (of 29 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    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

    (@axbx)

    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 TobiasBg

    (@tobiasbg)

    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

    (@axbx)

    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 TobiasBg

    (@tobiasbg)

    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

    (@axbx)

    A?e a?e a?e !
    Lots of thanks, for your answers.
    Best regards

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    sure, no problem!

    Best wishes,
    Tobias

    Thread Starter axbx

    (@axbx)

    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 TobiasBg

    (@tobiasbg)

    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

    (@axbx)

    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 TobiasBg

    (@tobiasbg)

    Hi,

    great! That’s good to hear ??

    Best wishes,
    Tobias

    Thread Starter axbx

    (@axbx)

    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 TobiasBg

    (@tobiasbg)

    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

    (@axbx)

    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 TobiasBg

    (@tobiasbg)

    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)
  • The topic ‘button onclick=”increment”’ is closed to new replies.