1

I'm trying to change the value of a variable when a button is clicked and pass the new variable to another function using jQuery, but it isn't working.

What am I doing wrong?

jQuery(document).ready(function($){
    var day;
    $('button#visual-live-time').on('click',function(){
        var day = $('#datetimepicker').val();
    });

    $('div.countdown').countdown(day, function(event){
        $(this).text(event.strftime('%D ημέρες %H ώρες %M λεπτά %S δευτερόλεπτα'));
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-lg-6">
    <div class="panel panel-default">
        <div class="panel-heading">Ημερομηνία και ώρα έναρξης</div>
        <div class="panel-body">
            <input type="text" size="35" name="event-title" id="datetimepicker">
        </div>
    </div>
</div>
<button type="text" id="visual-live-time"></div>
<div class="countdown"></div>
Random Logic
  • 122
  • 12

3 Answers3

1

Put your var day; outside the document ready. Because it is now only within the bounds of document ready function as below

var day;
jQuery(document).ready(function($){

    $('button#visual-live-time').on('click',function(){
        day = $('#datetimepicker').val();
    });

    $('div.countdown').countdown(day, function(event){
        $(this).text(event.strftime('%D ημέρες %H ώρες %M λεπτά %S δευτερόλεπτα'));
    });
});
Thanga
  • 6,775
  • 3
  • 14
  • 34
  • hey thanks the for code already tryed that but it still not working have a look https://jsfiddle.net/#&togetherjs=CTpizONmwb – user3778909 Jan 19 '16 at 03:02
0

You have two variables named "day". Remove the"var" before the second and it'll be the same variable

TinyTheBrontosaurus
  • 2,652
  • 5
  • 17
  • 32
0

To store the value over time, you will need to use a back-end server language like PHP.

Use PHP to store the value in a database, like MySQL, and then use PHP to get this value when you access teh Admin page. Place the value into the HTML field, and use javascript (countdown plugin) to animate the countdown that the human Admin will see.

Here is an answer that may help with an overview of what you need to do:

PHP - Secure member-only pages with a login system

For more information about PHP, you can review these (free) videos on TheNewBoston:

https://www.thenewboston.com/videos.php?cat=11

Community
  • 1
  • 1
cssyphus
  • 31,599
  • 16
  • 79
  • 97