I see what you did.
You moved stuff around as well.
Notice my code:
Code:
{/literal}
var calday = {$extra_fields.1.field_value};
var calmon = {$extra_fields.0.field_value};
var calyear = {$extra_fields.2.field_value};
{literal}
if(curday == "" || curmon=="" || curyear=="" || calday=="" || calmon=="" || calyear=="")
I ended the opening literal statement right before using smarty, and then started again after it. This is due, as I said before, smarty using {} and javascript as well... They don't play nice together.
Your code keeps the smarty calls in literal
Code:
var calday = {$extra_fields.0.field_value};
var calmon = {$extra_fields.1.field_value};
var calyear = {$extra_fields.2.field_value};
if its taken literally, it will be. The actual values are those.
Another thing you did was change the form.
Code:
<form name="birthday">
<input name="age" size="40" value="Result"><br>
</form>
That was the original.
Yours:
Code:
<form name="age">
<input name="age" size="40" value="Result"><br>
</form>
Thing is, the script only outputs the variable to a form named birthday. You changed it to age, thus another issue.
In any case... The code...
Already stripped out some code, removed extra spaces, changed it so the form it outputs to is called age, changed form name to age and fixed literal placing. Tested and works...
Code:
{*
For http://forum.x-cart.com/showthread.php?t=53578
Call extra fields via this:
{$extra_fields.0.field_value}
{$extra_fields.1.field_value}
{$extra_fields.2.field_value}
*}
<script type="text/javascript">
var startyear = "1950";
var endyear = "2010";
var dat = new Date();
var curday = dat.getDate();
var curmon = dat.getMonth()+1;
var curyear = dat.getFullYear();
var calday = {$extra_fields.1.field_value};
var calmon = {$extra_fields.0.field_value};
var calyear = {$extra_fields.2.field_value};
{literal}
function checkleapyear(datea)
{
if(datea.getYear()%4 == 0)
{
if(datea.getYear()% 10 != 0)
{
return true;
}
else
{
if(datea.getYear()% 400 == 0)
return true;
else
return false;
}
}
return false;
}
function DaysInMonth(Y, M) {
with (new Date(Y, M, 1, 12)) {
setDate(0);
return getDate();
}
}
function datediff(date1, date2) {
var y1 = date1.getFullYear(), m1 = date1.getMonth(), d1 = date1.getDate(),
y2 = date2.getFullYear(), m2 = date2.getMonth(), d2 = date2.getDate();
if (d1 < d2) {
m1--;
d1 += DaysInMonth(y2, m2);
}
if (m1 < m2) {
y1--;
m1 += 12;
}
return [y1 - y2, m1 - m2, d1 - d2];
}
function calage()
{
var curd = new Date(curyear,curmon-1,curday);
var cald = new Date(calyear,calmon-1,calday);
var diff = Date.UTC(curyear,curmon,curday,0,0,0) - Date.UTC(calyear,calmon,calday,0,0,0);
var dife = datediff(curd,cald);
document.age.age.value=dife[0]+" years, "+dife[1]+" months, and "+dife[2]+" days";
}
$(document).ready(function(){
calage();
});
{/literal}
</script>
<form name="age">
<input name="age" size="40" value="Result"><br>
</form>