1

I have been browsing this site for along time to help me learn various parts of coding and found it most helpful. I am struggling much so with Jquery & PHP to a point I cannot find my answer.

I am probably asking it wrong. But I need to be able to use JQuery countdown timer function to use one of my PHP variables, when a button is clicked, if this is possible?

    <b><span style="color:red"><div id="Count"></div></span></b>
    <script type="text/javascript">

    $('#Count').countdown({until: '+0h +0m +15s', significant: 2,
        expiryText: '<div class="over"><h3>Finished</h3></div>',
    layout: '{d<}{dn} {dl} {d>}{h<}{hn} {hl} {h>}{m<}{mn} {ml} {m>}{s<}{sn} {sl}{s>}'}); 

<button>Start</button>
    </script>

This is my current JQ option, but automatically activates when I load the page. I require it to start when I click the button.

Also from the top you will see it uses 15 seconds. I have tried to replace it with my PHP variable which is

$count1

But this did not work :(

Any advice would be most helpful as JQ is a new language to me and I am struggling to start. Thanks for your time.

1
  • (1) you would need to echo your php code in your jquery code - $('#Count').countdown({until: '+0h +0m +<?php $count1; ?>s', ... (2) your button is currently inside your </script> tag <button>Start</button> </script>, is that just a copy/paste issue here? (3) If you want your jquery code to only start after a button click, then wrap it - $('button').click(function(){ $('#Count').countdown({ ...[rest of code]... }); }); Commented May 25, 2015 at 22:30

1 Answer 1

2
<PHP echo $count1; ?>

Should work if you just stick it in where you would normally put the variable. It just echoes the value of count1 so whenever the client gets the JavaScript code the variable is just a number.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.