Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Forget about using html forms to submit your data. Your datasource is connected directy to your javascript so you can skip the postback and codebehind stuff. I would use jQuery for simplicity but you could do it with native javascript as well. jQuery is well documented if you decide to learn and use it, and worth the time to learn if you ask me.</p> <p>This example should help to get you started, feel free to edit and comment on it as needed:</p> <p><strong>Html</strong></p> <pre><code>&lt;fieldset class="stock-control"&gt; &lt;legend&gt;Edit Stock Amount&lt;/legend&gt; &lt;label&gt;ID:&lt;/label&gt; &lt;input type="text" id="txt-id"&gt; &lt;label&gt;Amount:&lt;/label&gt; &lt;input type="text" id="txt-change"&gt;&lt;br /&gt; &lt;input type="button" id="btn-add" value="Add"&gt; &lt;input type="button" id="btn-sub" value="Subtract"&gt; &lt;input type="button" id="btn-set" value="Set"&gt; &lt;br /&gt; &lt;label&gt;In stock: &lt;/label&gt;&lt;span id="lbl-total"&gt;&lt;/span&gt; &lt;/fieldset&gt; &lt;fieldset class="stock-control"&gt; &lt;legend&gt;Edit Stock Amount&lt;/legend&gt; &lt;label&gt;ID:&lt;/label&gt; &lt;input type="text" class="txt-id"&gt; &lt;label&gt;Amount:&lt;/label&gt; &lt;input type="text" class="txt-change"&gt;&lt;br /&gt; &lt;input type="button" class="btn-add" value="Add"&gt; &lt;input type="button" class="btn-sub" value="Subtract"&gt; &lt;input type="button" class="btn-set" value="Set"&gt; &lt;br /&gt; &lt;label&gt;In stock: &lt;/label&gt;&lt;span class="lbl-total"&gt;&lt;/span&gt; &lt;/fieldset&gt; </code></pre> <p><strong>Javascript</strong></p> <pre><code>// Your code $(function () { $('.stock-control').each(function () { var $control = $(this); var $id = $control.find('.txt-id'); var $amount = $control.find('.txt-amount'); var $total = $control.find('.lbl-total'); function RenderAmount() { $total.text(StockRecorder.GetAmount($id.val())); }; $('.btn-add').click(function () { var stock = parseInt($total.text()) + parseInt($amount.val()); StockRecorder.Update($id.val(), stock); RenderAmount(); }); $('.btn-sub').click(function () { var stock = parseInt($total.text()) - parseInt($amount.val()); StockRecorder.Update($id.val(), stock); RenderAmount(); }); $('.btn-set').click(function () { StockRecorder.Update($id.val(), parseInt($amount.val())); RenderAmount(); }); // Initialize RenderAmount(); }); }); </code></pre> <p><strong>NOTE:</strong> You would want a button or an event that calls the RenderAmount() functions when an id has been entered/changed in the id textbox. In my example i pretended it was already filled in.</p> <p>By the way, seems like a fun project you have gotten your hands on. Enjoy it! :) ​</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload