javascript - jquery counter reset issue -
i have following code , after page refresh, counter not getting reset. please me out in resetting "counter". excuse me if there typo(s) or dirty coding.
script :
$(window).load(function () { $(document).ready(function () { $('p').click(function () { $(this).animate({ 'color': 'rgb(' + (math.floor(math.random() * 256)) + ',' + (math.floor(math.random() * 256)) + ',' + (math.floor(math.random() * 256)) + ')' }, 500); }); $('#counter').data('count', 0); $("#fl1").click(function () { $('#counter').val(function (i, val) { return val == '0' ? 1 : val + 1; }); }); $('#counter').data('count', 0); $("#fl2").click(function () { $('#counter').val(function (i, val) { return val == '0' ? 2 : val + 2; }); }); }); });
solved script:
<script type='text/javascript'> $(window).load(function(){ $(document).ready(function() { $('p').click(function() { $(this).animate({ 'color': 'rgb(' + (math.floor(math.random() * 256)) + ',' + (math.floor(math.random() * 256)) + ',' + (math.floor(math.random() * 256)) + ')' }, 500); }); $('#counter').val('0'); $("#fl1").click(function() { $('#counter').val(function(i, val) { return val == '0' ? 1 : val + 1; }); }); $("#fl2").click(function() { $('#counter').val(function(i, val) { return val == '0' ? 2 : val + 2; }); }); }); }); </script>
html :
<div id="fl1" style="float:left; margin: 20px 0 0 0; font-weight: bold; display: inline; cursor: pointer;"> <p>(1)</p> </div> <div id="fl2" style="float:left; margin: 20px 0 0 40px; font-weight: bold; display: inline; cursor: pointer;"> <p>(2)</p> </div> <br /> <form method=post name="test" action="test.php"> <input type="hidden" name="counter" id="counter"> <input type="submit" value="send" > </form>
Comments
Post a Comment