I'm trying to create an easy bib clone. This means that I'll have 20+ boxes that all require an author name. So I've broken author name into the var lname and fname. My get.element.by.id is going to just consist of the same variables as the initial function, plus or minus different variables.
In the JS, I have the variable lname, for instance. lname is tied to the first box. If I try to "reuse" lname for the second box, it gives me the results for the first box. I can write a function for every box I create, but it seems like there should be a way to "reuse" a variable from another function. Is there?
function bib() {
var lname = document.getElementById("lname").value;
var fname = document.getElementById("fname").value;
var title = document.getElementById("title").value;
var city = document.getElementById("city").value;
var corp = document.getElementById("corp").value;
var pub = document.getElementById("pub").value;
document.getElementById("cite1").innerHTML = lname + ", " + fname + "." + title + "." + city + "." + corp + "." + pub + "." ;
document.getElementById("cite2").innerHTML = lname + ", " + fname + ", and" +lname2+","+fname2+"." + title + "." + city + "." + corp + "." + pub + "." ;
}
.grid{
display: grid;
flex-wrap: wrap;
grid: 500px / auto auto auto auto;
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
}
.grid > div {
background-color: rgba(255, 255, 255, 0.8);
text-align: left;
padding: 10px 10px 10px 10px;
font-size: 16px;
}
/*.float{
float:left;
}*/
.output {
height: 150px;
width: 255px;
flex-wrap: wrap;
word-wrap: break-word;
}
@media only screen and (max-width: 768px) {
/* For mobile phones: */
.grid {
width: 100%;
}
}
<h1> MLA Sourcing</h1>
<h2> Print Sourcing</h2>
<p> Enter the information in the appropriate box for your print source, click generate, copy to clipboard
<br>and paste into your work boxes</p>
<!--single author-->
<!--single author-->
<div class="grid">
<div>
<h3> Bib a Book or Article -<br> Single Author </h3>
<input class="float" placeholder="Author Last Name" id="lname"></input><br>
<input class="float" placeholder="Author First Name" id="fname"></input><br>
<input class="float" placeholder="Book/ Article Title" id="title"></input><br>
<input class="float" placeholder="City of Publication" id="city"></input><br>
<input class="float" placeholder="Press Company" id="comp"></input><br>
<input class="float" placeholder="(last) Year of Publication" id="pub"></input><br>
<p> <button onClick="bib()">Generate</button></p>
<h3> Citation</h3>
<p class="output" id="cite1"></p>
<button>copy to clipboard</button>
</div>
<div>
<h3> Bib a Book or Article -<br> Single Author </h3>
<input class="float" placeholder="Author Last Name" id="lname"></input><br>
<input class="float" placeholder="Author First Name" id="fname"></input><br>
<input class="float" placeholder="2nd Author Last Name" id="lname2"></input><br>
<input class="float" placeholder="2nd Author First Name" id="fname2"></input><br>
<input class="float" placeholder="Book/ Article Title" id="title"></input><br>
<input class="float" placeholder="City of Publication" id="city"></input><br>
<input class="float" placeholder="Press Company" id="corp"></input><br>
<input class="float" placeholder="(last) Year of Publication" id="pub"></input><br>
<p> <button onClick="bib()">Generate</button></p>
<h3> Citation</h3>
<p class="output" id="cite2"></p>
<button>copy to clipboard</button>
</div>
<div>
<h3> Bib a Book or Article -<br> Single Author </h3>
<input class="float" placeholder="Author Last Name" id="lname"></input><br>
<input class="float" placeholder="Author First Name" id="fname"></input><br>
<input class="float" placeholder="Book/ Article Title" id="title"></input><br>
<input class="float" placeholder="City of Publication" id="city"></input><br>
<input class="float" placeholder="Press Company" id="corp"></input><br>
<input class="float" placeholder="(last) Year of Publication" id="pub"></input><br>
<p> <button onClick="bib()">Generate</button></p>
<h3> Citation</h3>
<p class="output" id="cite1"></p>
<button>copy to clipboard</button>
</div>
<div>
<h3> Bib a Book or Article -<br> Single Author </h3>
<input class="float" placeholder="Author Last Name" id="lname"></input><br>
<input class="float" placeholder="Author First Name" id="fname"></input><br>
<input class="float" placeholder="Book/ Article Title" id="title"></input><br>
<input class="float" placeholder="City of Publication" id="city"></input><br>
<input class="float" placeholder="Press Company" id="corp"></input><br>
<input class="float" placeholder="(last) Year of Publication" id="pub"></input><br>
<p class="float"> <button onClick="bib()">Generate</button></p>
<h3> Citation</h3>
<p class="output" id="cite1"></p>
<button>copy to clipboard</button>
</div>
</div>