Please remember we dont create code for you, we fix it and give u ideas on how to do stuff... here is my idea on what you want:
it seems you want a javascript function using a mix of document.write and onclick statements, you may need to consult a demo page or tutorial site on how this would work... no tutorial pages or anything spring to mind but hey i bet loads of oter people know great tutorials on that stuff 😉