Citation Generator
Generate properly formatted citations for books, websites and journals in APA, MLA and Chicago styles instantly.
Advertisement
Advertisement
let source='book',format='apa';
function setSource(s,btn){source=s;document.querySelectorAll('.src-btn').forEach(b=>b.classList.remove('active'));btn.classList.add('active');['book','website','journal'].forEach(t=>document.getElementById('fields-'+t).style.display=t===s?'':'none');}
function setFormat(f,btn){format=f;document.querySelectorAll('.fmt-btn').forEach(b=>b.classList.remove('active'));btn.classList.add('active');}
function v(id){return(document.getElementById(id)||{}).value||'';}
function generateCitation(){
let cite='';
const today=new Date().toLocaleDateString('en-US',{year:'numeric',month:'long',day:'numeric'});
if(source==='book'){
const last=v('b-last'),first=v('b-first'),title=v('b-title'),year=v('b-year'),pub=v('b-pub'),city=v('b-city');
if(!last||!title){alert('Please enter at least author last name and book title.');return;}
if(format==='apa')cite=`${last}, ${first?first[0]+'.':''} (${year||'n.d.'}).