i'm trying create calculator, getting values buttons 1 9. i'd add value textbox instead of setting it, want user able add 1 5 make total of 15. how can achieve this?
.prop sets value, or .val 1 out of list.
<script> jquery(document).ready(function () { jquery("#one").click(function () { jquery("#entered").prop("value", "1"); }); }); </script> css part:
<div> <button id="one">1</button> <button id="two">2</button> <button id="three">3</button> <button id="four">4</button> <button id="five">5</button> <button id="six">6</button> <button id="seven">7</button> <button id="eight">8</button> <button id="nine">9</button> <input type="text" id="entered" disabled="disabled" /> </div>
change
jquery("#entered").prop("value", "1"); to
jquery("#entered").val(jquery("#entered").val() + "1"); this concenate old stuff new entered 1
this full code:
<div> <button id="one">1</button> <button id="two">2</button> <button id="three">3</button> <button id="four">4</button> <button id="five">5</button> <button id="six">6</button> <button id="seven">7</button> <button id="eight">8</button> <button id="nine">9</button> <input type="text" id="entered" disabled="disabled" value="" /> </div> jquery(document).ready(function () { jquery("#one").click(function () { jquery("#entered").val(jquery("#entered").val() + "1"); }); }); if want have function that:
$.fn.appendval = function (newpart) { return this.each(function(){ $(this).val( $(this).val() + newpart); }); }; $("#abc").appendval("test"); https://jsfiddle.net/ffp19wze/ here working jsfiddle it
Comments
Post a Comment