Turns a variable into an editable piece of text in a text box and a save button, when clicked displays the new amount back in a nice box without a refresh.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<div class='changeme' >1000</div> <!-- variable --> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> $(document).delegate('.done', 'click', function() { $('#txtname').replaceWith(function() { $(".done").hide(); // add to api to change budget return '<div class="done">' + $(this).val() + ' - Saved...</div>'; }); }); $(".changeme").click(function() { var thevalue = $( this ).text(); $(this).replaceWith($('<form action="replacewith.php" method="get"><input id="txtname" value=' + $(this).text() + '> <input class="done" type="button" value="Save Budget"></form>')); }); </script> <style> #txtname { color: red; border: 2px solid blue; width: 110px; text-align: center; } div { color: red; border: 2px solid blue; width: 110px; margin: 3px; text-align: center; } </style> |