I am got using following code in a javascript file(custom.js):
gapinvite = new Date(2014, 06 - 1, 2);
$('.days').countdown({
until: gapinvite,
layout: '{dn} {dl}',
timezone: +7
});
I am using theme options(theme-options.php) to get the input from a user and then need to use it in the above javascript file.If it was a php file I would've used:
$date = get_option('director_date');
if( $date) {
echo $date;
}
. Since it is a javascript file I do not know how that could be possible. Could you please help?
-
There are a lot of introductions to AJAX which you can find in Google. And that's how to use AJAX in WP codex.wordpress.org/AJAX_in_Plugins.oxfn– oxfn2014年03月14日 05:41:35 +00:00Commented Mar 14, 2014 at 5:41
-
I'm not good at ajax.An answer would be appreciateduser3274745– user32747452014年03月14日 05:44:50 +00:00Commented Mar 14, 2014 at 5:44
-
you want to add php code to javascript file ?Karthick Kumar– Karthick Kumar2014年03月14日 05:47:49 +00:00Commented Mar 14, 2014 at 5:47
-
Yes.Or an alternative would be appreciateduser3274745– user32747452014年03月14日 05:48:38 +00:00Commented Mar 14, 2014 at 5:48
-
you can add javascript to php file and the include the php file where you wantKarthick Kumar– Karthick Kumar2014年03月14日 05:50:56 +00:00Commented Mar 14, 2014 at 5:50
1 Answer 1
Output the value into a javascript variable during rendering.
<script>var directorDate = new Date(<?php echo date('Y, m, d', $date); ?>);</script>
Then in the javascript, reference directorDate variable.
The script tag above needs to be inserted before your custom.js, or custom.js needs to wait before looking for the variable (it will be undefined otherwise).