-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsavings-goal-calculator.html
More file actions
625 lines (598 loc) · 30.9 KB
/
Copy pathsavings-goal-calculator.html
File metadata and controls
625 lines (598 loc) · 30.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- SEO Meta Tags -->
<title>Savings Goal Calculator | Calculate How to Reach Your Savings Goals 2025</title>
<meta name="description" content="Free savings goal calculator. Calculate how much to save monthly to reach your goals. Plan for house down payment, emergency fund, vacation, or any savings target.">
<meta name="keywords" content="savings goal calculator, savings calculator, how much to save calculator, monthly savings calculator, savings plan calculator, emergency fund calculator, down payment calculator, vacation savings calculator">
<meta name="robots" content="index, follow">
<link rel="canonical" href="https://fireplanner.org/savings-goal-calculator.html">
<meta property="og:title" content="Savings Goal Calculator - Plan How to Reach Your Goals">
<meta property="og:url" content="https://fireplanner.org/savings-goal-calculator.html">
<script async src="https://www.googletagmanager.com/gtag/js?id=G-B0FS8F3KDN"></script>
<script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());gtag('config','G-B0FS8F3KDN');</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2955475775322391" crossorigin="anonymous"></script>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="shortcut icon" href="/favicon.ico">
<!-- Prevent flash of wrong theme -->
<script>
(function(){
var K='fireplanner-theme',D=document.documentElement;
var t;try{t=localStorage.getItem(K)}catch(e){}
if(t!=='dark'&&t!=='light')t=window.matchMedia('(prefers-color-scheme:dark)').matches?'dark':'light';
D.setAttribute('data-theme',t);
window.toggleFPTheme=function(){
var c=D.getAttribute('data-theme')==='dark'?'light':'dark';
D.setAttribute('data-theme',c);
try{localStorage.setItem(K,c)}catch(e){}
};
})();
</script>
<link rel="stylesheet" href="styles.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=Work+Sans:wght@400;600&display=swap" rel="stylesheet">
<script>
/* ── FIRE Planner Utilities ── */
/* =====================================================
FIRE PLANNER — Core Utilities (loads early in <head>)
animateValue, FPValidate, FPShare, FPSteps
All defined on window so inline scripts can call them
===================================================== */
/* ---- Animated number counter ---- */
window.animateValue = function(el, newText, duration) {
if (!el) return;
duration = duration || 600;
var numMatch = newText.match(/[\d,]+\.?\d*/);
if (!numMatch) { el.textContent = newText; return; }
var targetNum = parseFloat(numMatch[0].replace(/,/g, ''));
var prefix = newText.slice(0, newText.indexOf(numMatch[0]));
var suffix = newText.slice(newText.indexOf(numMatch[0]) + numMatch[0].length);
var curMatch = el.textContent.match(/[\d,]+\.?\d*/);
var startNum = curMatch ? parseFloat(curMatch[0].replace(/,/g, '')) : 0;
if (startNum === targetNum) { el.textContent = newText; return; }
var startTime = performance.now();
var isCurrency = prefix.indexOf('$') !== -1 || newText.indexOf('$') === 0;
function step(now) {
var progress = Math.min((now - startTime) / duration, 1);
var ease = 1 - Math.pow(1 - progress, 3);
var current = startNum + (targetNum - startNum) * ease;
if (isCurrency) {
el.textContent = new Intl.NumberFormat('en-US', {
style: 'currency', currency: 'USD',
minimumFractionDigits: 0, maximumFractionDigits: 0
}).format(Math.round(current)) + suffix;
} else {
el.textContent = prefix + Math.round(current).toLocaleString('en-US') + suffix;
}
if (progress < 1) requestAnimationFrame(step);
else el.textContent = newText;
}
requestAnimationFrame(step);
};
/* ---- Input validation engine ---- */
window.FPValidate = {
rules: {},
init: function(rules) {
this.rules = rules;
var self = this;
Object.keys(rules).forEach(function(id) {
var el = document.getElementById(id);
if (!el) return;
var wrap = el.closest('.form-group');
if (!wrap) return;
if (!document.getElementById('err-' + id)) {
var err = document.createElement('div');
err.className = 'fp-error-msg';
err.id = 'err-' + id;
err.innerHTML = '<span>⚠</span><span class="fp-err-text"></span>';
wrap.appendChild(err);
}
el.addEventListener('blur', function() { self.check(id); });
el.addEventListener('input', function() {
if (el.classList.contains('fp-invalid')) self.check(id);
else self.checkValid(id);
});
});
},
check: function(id) {
var el = document.getElementById(id);
var rule = this.rules[id];
if (!el || !rule) return true;
var val = parseFloat(el.value);
var err = document.getElementById('err-' + id);
var msg = '';
if (el.value === '' || isNaN(val)) {
msg = (rule.label || 'This field') + ' is required.';
} else if (rule.min !== undefined && val < rule.min) {
msg = 'Enter at least ' + rule.min + (rule.unit || '.');
} else if (rule.max !== undefined && val > rule.max) {
msg = 'Maximum is ' + rule.max + (rule.unit || '.');
} else if (rule.custom) {
msg = rule.custom(val, el) || '';
}
if (msg) {
el.classList.add('fp-invalid'); el.classList.remove('fp-valid');
if (err) { err.querySelector('.fp-err-text').textContent = msg; err.classList.add('visible'); }
return false;
} else {
el.classList.remove('fp-invalid'); el.classList.add('fp-valid');
if (err) err.classList.remove('visible');
return true;
}
},
checkValid: function(id) {
var el = document.getElementById(id);
var rule = this.rules[id];
if (!el || !rule) return;
var val = parseFloat(el.value);
if (!isNaN(val) && (rule.min === undefined || val >= rule.min) && (rule.max === undefined || val <= rule.max)) {
el.classList.remove('fp-invalid'); el.classList.add('fp-valid');
var err = document.getElementById('err-' + id);
if (err) err.classList.remove('visible');
}
},
checkAll: function() {
var self = this;
return Object.keys(this.rules).every(function(id) { return self.check(id); });
}
};
/* ---- Share / canvas card generator ---- */
window.FPShare = {
open: function(title, results) {
var modal = document.getElementById('fp-share-modal');
if (!modal) { this._createModal(); modal = document.getElementById('fp-share-modal'); }
this._drawCard(title, results);
modal.classList.add('open');
},
_createModal: function() {
var el = document.createElement('div');
el.className = 'fp-modal-overlay';
el.id = 'fp-share-modal';
el.innerHTML =
'<div class="fp-modal">' +
'<h3>📤 Share Your Results</h3>' +
'<p>Download your results card to share on Instagram, Reddit, or with friends.</p>' +
'<div class="fp-share-card-preview"><canvas id="fp-share-canvas" width="800" height="450"></canvas></div>' +
'<div class="fp-modal-actions">' +
'<button class="fp-modal-download" onclick="FPShare.download()">↓ Download Image</button>' +
'<button class="fp-modal-close" onclick="FPShare.close()">Close</button>' +
'</div></div>';
document.body.appendChild(el);
el.addEventListener('click', function(e) { if (e.target === el) FPShare.close(); });
},
_drawCard: function(title, results) {
var canvas = document.getElementById('fp-share-canvas');
var ctx = canvas.getContext('2d');
var w = 800, h = 450;
var bg = ctx.createLinearGradient(0, 0, w, h);
bg.addColorStop(0, '#1a2332'); bg.addColorStop(1, '#2c3e5f');
ctx.fillStyle = bg; ctx.fillRect(0, 0, w, h);
var r1 = ctx.createRadialGradient(w*.8, h*.2, 0, w*.8, h*.2, 280);
r1.addColorStop(0, 'rgba(255,107,53,0.20)'); r1.addColorStop(1, 'transparent');
ctx.fillStyle = r1; ctx.fillRect(0, 0, w, h);
var r2 = ctx.createRadialGradient(w*.1, h*.8, 0, w*.1, h*.8, 200);
r2.addColorStop(0, 'rgba(37,99,235,0.20)'); r2.addColorStop(1, 'transparent');
ctx.fillStyle = r2; ctx.fillRect(0, 0, w, h);
ctx.fillStyle = 'rgba(255,255,255,0.88)';
ctx.font = 'bold 17px sans-serif';
ctx.fillText('\uD83D\uDD25 FIRE Planner \u00B7 fireplanner.org', 48, 50);
ctx.strokeStyle = 'rgba(255,255,255,0.14)'; ctx.lineWidth = 1;
ctx.beginPath(); ctx.moveTo(48, 65); ctx.lineTo(w-48, 65); ctx.stroke();
ctx.fillStyle = '#fff'; ctx.font = 'bold 32px serif';
ctx.fillText(title, 48, 108);
var cols = Math.min(results.length, 4);
var cardW = (w - 96 - (cols-1)*14) / cols;
var sy = 136;
var colors = ['#ff6b35','#2563eb','#059669','#d97706'];
results.slice(0, cols).forEach(function(r, i) {
var x = 48 + i*(cardW+14);
ctx.fillStyle = 'rgba(255,255,255,0.07)';
_rrect(ctx, x, sy, cardW, 118, 10); ctx.fill();
ctx.fillStyle = colors[i]; _rrect(ctx, x, sy, cardW, 4, 2); ctx.fill();
ctx.fillStyle = 'rgba(255,255,255,0.52)';
ctx.font = '600 11px sans-serif';
ctx.fillText(r.label.toUpperCase().slice(0,22), x+14, sy+28);
ctx.fillStyle = '#fff';
ctx.font = 'bold ' + (r.value.length > 10 ? '20' : '26') + 'px serif';
ctx.fillText(r.value, x+14, sy+74);
});
ctx.fillStyle = 'rgba(255,255,255,0.32)'; ctx.font = '12px sans-serif';
ctx.fillText('fireplanner.org \u00B7 For educational purposes only. Not financial advice.', 48, h-22);
},
download: function() {
var canvas = document.getElementById('fp-share-canvas');
var a = document.createElement('a');
a.download = 'fire-planner-results.png';
a.href = canvas.toDataURL('image/png');
a.click();
},
close: function() {
var modal = document.getElementById('fp-share-modal');
if (modal) modal.classList.remove('open');
}
};
function _rrect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x+r,y); ctx.lineTo(x+w-r,y);
ctx.quadraticCurveTo(x+w,y,x+w,y+r); ctx.lineTo(x+w,y+h-r);
ctx.quadraticCurveTo(x+w,y+h,x+w-r,y+h); ctx.lineTo(x+r,y+h);
ctx.quadraticCurveTo(x,y+h,x,y+h-r); ctx.lineTo(x,y+r);
ctx.quadraticCurveTo(x,y,x+r,y); ctx.closePath();
}
/* ---- Multi-step wizard ---- */
window.FPSteps = {
current: 0, total: 0,
init: function(total, stepNames) {
this.total = total; this.current = 0;
this._renderBar(stepNames); this._show(0);
},
_renderBar: function(names) {
var bar = document.getElementById('fp-steps-bar');
if (!bar) return;
var html = '<div class="fp-progress-track" id="fp-progress-track"></div>';
for (var i = 0; i < this.total; i++) {
html += '<div class="fp-step' + (i===0?' active':'') + '" data-step="'+i+'" onclick="FPSteps.goto('+i+')">' +
'<div class="fp-step-dot">' + (i+1) + '</div>' +
'<div class="fp-step-label">' + (names[i]||'Step '+(i+1)) + '</div></div>';
}
bar.innerHTML = html; this._updateTrack();
},
goto: function(n) {
if (n<0||n>=this.total) return;
this._hide(this.current); this.current=n;
this._show(n); this._updateBar(); this._updateTrack();
},
next: function() { this.goto(this.current+1); },
prev: function() { this.goto(this.current-1); },
_show: function(n) { var p=document.getElementById('fp-panel-'+n); if(p) p.classList.add('active'); },
_hide: function(n) { var p=document.getElementById('fp-panel-'+n); if(p) p.classList.remove('active'); },
_updateBar: function() {
document.querySelectorAll('.fp-step').forEach(function(el) {
var s=parseInt(el.getAttribute('data-step'));
el.classList.remove('active','done');
if(s===FPSteps.current) el.classList.add('active');
else if(s<FPSteps.current) el.classList.add('done');
});
},
_updateTrack: function() {
var t=document.getElementById('fp-progress-track'); if(!t) return;
t.style.width=(this.total<=1?100:(this.current/(this.total-1))*100)+'%';
}
};
</script>
<script>
/* ── FIRE Planner: Utilities (inline, no external deps) ── */
/* Format currency */
function fpFmt(v) {
return new Intl.NumberFormat('en-US',{style:'currency',currency:'USD',minimumFractionDigits:0,maximumFractionDigits:0}).format(isNaN(v)?0:v);
}
/* Animated number counter */
window.animateValue = function(el, newText) {
if (!el) return;
var numMatch = newText.match(/[\d,]+\.?\d*/);
if (!numMatch) { el.textContent = newText; return; }
var target = parseFloat(numMatch[0].replace(/,/g,''));
var prefix = newText.slice(0, newText.indexOf(numMatch[0]));
var suffix = newText.slice(newText.indexOf(numMatch[0]) + numMatch[0].length);
var curMatch = el.textContent.match(/[\d,]+\.?\d*/);
var start = curMatch ? parseFloat(curMatch[0].replace(/,/g,'')) : 0;
if (start === target) { el.textContent = newText; return; }
var t0 = performance.now();
var isCur = prefix.indexOf('$') !== -1 || newText.indexOf('$') === 0;
(function step(now) {
var p = Math.min((now-t0)/600, 1), e = 1-Math.pow(1-p,3);
var cur = start + (target-start)*e;
el.textContent = isCur
? new Intl.NumberFormat('en-US',{style:'currency',currency:'USD',minimumFractionDigits:0,maximumFractionDigits:0}).format(Math.round(cur))+suffix
: prefix+Math.round(cur).toLocaleString('en-US')+suffix;
if (p < 1) requestAnimationFrame(step); else el.textContent = newText;
})(t0);
};
/* Input validation */
window.FPValidate = {
rules:{},
init: function(rules) {
this.rules = rules; var self = this;
Object.keys(rules).forEach(function(id) {
var el = document.getElementById(id); if (!el) return;
var wrap = el.closest('.form-group'); if (!wrap) return;
if (!document.getElementById('err-'+id)) {
var err = document.createElement('div');
err.className='fp-error-msg'; err.id='err-'+id;
err.innerHTML='<span>⚠</span><span class="fp-err-text"></span>';
wrap.appendChild(err);
}
el.addEventListener('blur', function(){ self.check(id); });
el.addEventListener('input', function(){
if (el.classList.contains('fp-invalid')) self.check(id); else self.checkValid(id);
});
});
},
check: function(id) {
var el=document.getElementById(id), rule=this.rules[id];
if (!el||!rule) return true;
var val=parseFloat(el.value), err=document.getElementById('err-'+id), msg='';
if (el.value===''||isNaN(val)) msg=(rule.label||'This field')+' is required.';
else if (rule.min!==undefined&&val<rule.min) msg='Enter at least '+rule.min+(rule.unit||'.');
else if (rule.max!==undefined&&val>rule.max) msg='Maximum is '+rule.max+(rule.unit||'.');
else if (rule.custom) msg=rule.custom(val,el)||'';
if (msg) {
el.classList.add('fp-invalid'); el.classList.remove('fp-valid');
if (err){err.querySelector('.fp-err-text').textContent=msg;err.classList.add('visible');}
return false;
} else {
el.classList.remove('fp-invalid'); el.classList.add('fp-valid');
if (err) err.classList.remove('visible');
return true;
}
},
checkValid: function(id) {
var el=document.getElementById(id),rule=this.rules[id]; if(!el||!rule) return;
var val=parseFloat(el.value);
if(!isNaN(val)&&(rule.min===undefined||val>=rule.min)&&(rule.max===undefined||val<=rule.max)){
el.classList.remove('fp-invalid');el.classList.add('fp-valid');
var err=document.getElementById('err-'+id);if(err)err.classList.remove('visible');
}
}
};
/* Share card */
window.FPShare = {
open: function(title, results) {
var modal=document.getElementById('fp-share-modal');
if (!modal) { this._make(); modal=document.getElementById('fp-share-modal'); }
this._draw(title, results);
modal.classList.add('open');
},
_make: function() {
var el=document.createElement('div');
el.className='fp-modal-overlay'; el.id='fp-share-modal';
el.innerHTML='<div class="fp-modal"><h3>📤 Share Your Results</h3><p>Download your results card to share with friends.</p><div class="fp-share-card-preview"><canvas id="fp-share-canvas" width="800" height="450"></canvas></div><div class="fp-modal-actions"><button class="fp-modal-download" onclick="FPShare.download()">↓ Download Image</button><button class="fp-modal-close" onclick="FPShare.close()">Close</button></div></div>';
document.body.appendChild(el);
el.addEventListener('click',function(e){if(e.target===el)FPShare.close();});
},
_draw: function(title, results) {
var c=document.getElementById('fp-share-canvas'),ctx=c.getContext('2d'),w=800,h=450;
var bg=ctx.createLinearGradient(0,0,w,h);
bg.addColorStop(0,'#1a2332');bg.addColorStop(1,'#2c3e5f');
ctx.fillStyle=bg;ctx.fillRect(0,0,w,h);
var r1=ctx.createRadialGradient(w*.8,h*.2,0,w*.8,h*.2,280);
r1.addColorStop(0,'rgba(255,107,53,.20)');r1.addColorStop(1,'transparent');
ctx.fillStyle=r1;ctx.fillRect(0,0,w,h);
ctx.fillStyle='rgba(255,255,255,.88)';ctx.font='bold 17px sans-serif';
ctx.fillText('\uD83D\uDD25 FIRE Planner \u00B7 fireplanner.org',48,50);
ctx.strokeStyle='rgba(255,255,255,.14)';ctx.lineWidth=1;
ctx.beginPath();ctx.moveTo(48,65);ctx.lineTo(w-48,65);ctx.stroke();
ctx.fillStyle='#fff';ctx.font='bold 30px serif';ctx.fillText(title,48,105);
var cols=Math.min(results.length,4),cw=(w-96-(cols-1)*14)/cols,sy=130;
var colors=['#ff6b35','#2563eb','#059669','#d97706'];
results.slice(0,cols).forEach(function(r,i){
var x=48+i*(cw+14);
ctx.fillStyle='rgba(255,255,255,.07)';_rr(ctx,x,sy,cw,118,10);ctx.fill();
ctx.fillStyle=colors[i];_rr(ctx,x,sy,cw,4,2);ctx.fill();
ctx.fillStyle='rgba(255,255,255,.52)';ctx.font='600 11px sans-serif';
ctx.fillText(r.label.toUpperCase().slice(0,22),x+14,sy+28);
ctx.fillStyle='#fff';ctx.font='bold '+(r.value.length>10?'20':'25')+'px serif';
ctx.fillText(r.value,x+14,sy+72);
});
ctx.fillStyle='rgba(255,255,255,.30)';ctx.font='12px sans-serif';
ctx.fillText('fireplanner.org \u00B7 For educational purposes only.',48,h-22);
},
download: function(){
var a=document.createElement('a');
a.download='fire-planner-results.png';
a.href=document.getElementById('fp-share-canvas').toDataURL('image/png');
a.click();
},
close: function(){var m=document.getElementById('fp-share-modal');if(m)m.classList.remove('open');}
};
function _rr(ctx,x,y,w,h,r){
ctx.beginPath();ctx.moveTo(x+r,y);ctx.lineTo(x+w-r,y);
ctx.quadraticCurveTo(x+w,y,x+w,y+r);ctx.lineTo(x+w,y+h-r);
ctx.quadraticCurveTo(x+w,y+h,x+w-r,y+h);ctx.lineTo(x+r,y+h);
ctx.quadraticCurveTo(x,y+h,x,y+h-r);ctx.lineTo(x,y+r);
ctx.quadraticCurveTo(x,y,x+r,y);ctx.closePath();
}
/* Multi-step wizard */
window.FPSteps = {
cur:0, total:0,
init:function(total,names){this.total=total;this.cur=0;this._bar(names);this._show(0);},
_bar:function(names){
var b=document.getElementById('fp-steps-bar');if(!b)return;
var h='<div class="fp-progress-track" id="fp-progress-track"></div>';
for(var i=0;i<this.total;i++)h+='<div class="fp-step'+(i===0?' active':'')+'\" data-step="'+i+'" onclick="FPSteps.goto('+i+')"><div class="fp-step-dot">'+(i+1)+'</div><div class="fp-step-label">'+(names[i]||'Step '+(i+1))+'</div></div>';
b.innerHTML=h;this._track();
},
goto:function(n){if(n<0||n>=this.total)return;this._hide(this.cur);this.cur=n;this._show(n);this._dots();this._track();},
next:function(){this.goto(this.cur+1);},prev:function(){this.goto(this.cur-1);},
_show:function(n){var p=document.getElementById('fp-panel-'+n);if(p)p.classList.add('active');},
_hide:function(n){var p=document.getElementById('fp-panel-'+n);if(p)p.classList.remove('active');},
_dots:function(){document.querySelectorAll('.fp-step').forEach(function(el){var s=parseInt(el.dataset.step);el.classList.remove('active','done');if(s===FPSteps.cur)el.classList.add('active');else if(s<FPSteps.cur)el.classList.add('done');});},
_track:function(){var t=document.getElementById('fp-progress-track');if(t)t.style.width=(this.total<=1?100:this.cur/(this.total-1)*100)+'%';}
};
/* Zero-on-empty: call after setting up inputs */
window.fpZeroEmpty = function(selector) {
document.querySelectorAll(selector).forEach(function(inp) {
inp.addEventListener('blur', function() {
if (this.value === '' || this.value === null) this.value = '0';
});
inp.addEventListener('blur', function() {
if (this.value === '') this.value = '0';
});
});
};
</script>
</head>
<body class="calculator-page">
<header class="site-header">
<div class="container">
<div class="header-content">
<div class="logo">
<a href="index.html" style="display: flex; align-items: center; text-decoration: none; gap: 14px;">
<img src="fire-logo.png" alt="FIRE Planner" style="height: 52px; width: auto;">
<div>
<h1>FIRE Planner</h1>
<p class="tagline">Your Path to Financial Independence</p>
</div>
</a>
</div>
<nav class="main-nav">
<a href="index.html#calculators">Calculators</a>
<a href="resources.html">Resources</a>
<a href="glossary.html">Glossary</a>
<a href="about.html">About</a>
<a href="https://www.instagram.com/fireplanner_org/" target="_blank" rel="noopener" class="nav-instagram" aria-label="Follow us on Instagram">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="2" width="20" height="20" rx="5" ry="5"></rect><path d="M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z"></path><line x1="17.5" y1="6.5" x2="17.51" y2="6.5"></line></svg>
</a>
<button type="button" class="theme-toggle" aria-label="Toggle dark mode" onclick="toggleFPTheme()"><span class="toggle-icon sun">☀</span><span class="toggle-icon moon">☾</span></button>
</nav>
</div>
</div>
</header>
<div class="calculator-header">
<div class="container">
<h1>🎯 Savings Goal Calculator</h1>
<p>Calculate how much to save monthly to reach your financial goals</p>
</div>
</div>
<section class="calculator-container">
<div class="container">
<div class="calculator-layout">
<div class="input-panel">
<h2>Your Savings Goal</h2>
<form id="savings-form">
<div class="form-group">
<label for="goal-amount">Savings Goal Amount ($)</label>
<input type="number" id="goal-amount" value="50000" min="0" step="1000" onblur="if(this.value==='')this.value='0'">
</div>
<div class="form-group">
<div class="fp-label-wrap"><label for="current-savings">Current Savings ($)</label><span class="fp-tip"><span class="fp-tip-bubble">What you've already saved toward this goal today.</span></span></div>
<input type="number" id="current-savings" value="5000" min="0" step="500" onblur="if(this.value==='')this.value='0'">
</div>
<div class="form-group">
<label for="time-frame">Time Frame (Months)</label>
<input type="number" id="time-frame" value="36" min="1" max="600" onblur="if(this.value==='')this.value='0'">
</div>
<div class="form-group">
<label for="interest-rate">Expected Return (%/year)</label>
<input type="number" id="interest-rate" value="4" min="0" max="20" step="0.1" onblur="if(this.value==='')this.value='0'">
</div>
</form>
</div>
<div class="results-panel">
<h2>Your Savings Plan</h2>
<div class="result-card">
<div class="result-label">Monthly Savings Needed</div>
<div class="result-value" id="monthly-needed">$0</div>
</div>
<div class="result-card">
<div class="result-label">Total You'll Save</div>
<div class="result-value" id="total-savings">$0</div>
</div>
<div class="result-card">
<div class="result-label">Interest Earned</div>
<div class="result-value" id="interest-earned">$0</div>
</div>
<div class="result-card">
<div class="result-label">Goal Completion Date</div>
<div class="result-value" id="completion-date" style="font-size:20px;">--</div>
</div>
<div class="fp-share-section" style="margin-top:24px;">
<button class="fp-share-btn" onclick="fpSavingsShare()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><line x1="8.59" y1="13.51" x2="15.42" y2="17.49"/><line x1="15.41" y1="6.51" x2="8.59" y2="10.49"/></svg>
Share My Results
</button>
</div>
</div>
</div>
</div>
</section>
<footer class="site-footer">
<div class="container">
<div class="footer-content">
<div class="footer-section">
<h4>FIRE Planner</h4>
<p>Free tools to help you achieve Financial Independence and Retire Early.</p>
</div>
<div class="footer-section">
<h4>Calculators</h4>
<ul>
<li><a href="fire-calculator.html">FIRE Calculator</a></li>
<li><a href="compound-interest.html">Compound Interest</a></li>
<li><a href="coast-fire-calculator.html">Coast FIRE</a></li>
<li><a href="401k-calculator.html">401k Calculator</a></li>
<li><a href="net-worth-calculator.html">Net Worth</a></li>
<li><a href="roth-vs-traditional.html">Roth vs Traditional</a></li>
<li><a href="debt-calculator.html">Debt Payoff</a></li>
<li><a href="fee-calculator.html">Investment Fees</a></li>
<li><a href="savings-goal-calculator.html">Savings Goal</a></li>
<li><a href="retirement-age-calculator.html">Retirement Age</a></li>
</ul>
</div>
<div class="footer-section">
<h4>Resources</h4>
<ul>
<li><a href="resources.html">FIRE Resources</a></li>
<li><a href="fire-guide.html">FIRE Guide</a></li>
<li><a href="glossary.html">Glossary</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div>
<div class="footer-section">
<h4>Legal</h4>
<ul>
<li><a href="privacy-policy.html">Privacy Policy</a></li>
<li><a href="terms-of-service.html">Terms of Service</a></li>
<li><a href="disclaimer.html">Disclaimer</a></li>
</ul>
</div>
<div class="footer-section">
<h4>Follow Us</h4>
<ul>
<li>
<a href="https://www.instagram.com/fireplanner_org/" target="_blank" rel="noopener" style="display: flex; align-items: center; gap: 8px;">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="2" width="20" height="20" rx="5" ry="5"></rect><path d="M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z"></path><line x1="17.5" y1="6.5" x2="17.51" y2="6.5"></line></svg>
@fireplanner_org
</a>
</li>
</ul>
</div>
</div>
<div class="footer-bottom">
<p>© 2025 FIRE Planner. All calculators are for educational purposes. Consult a financial advisor for personalized advice.</p>
</div>
</div>
</footer>
<script>
document.addEventListener('DOMContentLoaded', function() {
function calc() {
var goal = parseFloat(document.getElementById('goal-amount').value) || 0;
var current = parseFloat(document.getElementById('current-savings').value) || 0;
var months = parseFloat(document.getElementById('time-frame').value) || 12;
var annRate = (parseFloat(document.getElementById('interest-rate').value) || 4) / 100;
var mRate=annRate/12, fvNow=current*Math.pow(1+mRate,months), needed=goal-fvNow;
var monthly=0;
if(mRate>0&&months>0) monthly=needed/((Math.pow(1+mRate,months)-1)/mRate);
else if(months>0) monthly=needed/months;
monthly=Math.max(0,monthly);
var totalPaid=current+monthly*months, interest=Math.max(0,goal-totalPaid);
animateValue(document.getElementById('monthly-needed'),fpFmt(monthly));
animateValue(document.getElementById('total-savings'), fpFmt(totalPaid));
var ie=document.getElementById('interest-earned'); if(ie) animateValue(ie,fpFmt(interest));
var d=new Date(); d.setMonth(d.getMonth()+Math.ceil(months));
var de=document.getElementById('completion-date'); if(de) de.textContent=d.toLocaleDateString('en-US',{month:'long',year:'numeric'});
}
document.querySelectorAll('#savings-form input').forEach(function(i){i.addEventListener('input',calc);});
document.querySelectorAll('input[type="number"]').forEach(function(inp) {
inp.addEventListener('focus', function() { this.select(); });
inp.addEventListener('blur', function() { if (this.value === '') { this.value = '0'; calc(); } });
});
window.fpSavingsShare=function(){FPShare.open('My Savings Goal Plan',[{label:'Monthly Needed',value:document.getElementById('monthly-needed').textContent},{label:'Total Saved',value:document.getElementById('total-savings').textContent}]);};
calc();
});
</script>
</body>
</html>