I’m trying to make a reference generator. People fills in some information, and then the generator sets up the text in the right way. Here’s what I’ve got so far:
$('#ref-button1').click(function () {
var authorname = $('#bookAuthor').val();
if (authorname == "") {
$('.error').show();
return false;
}
var booktitle = $('#bookTitle').val();
if (booktitle == "") {
$('.error').show();
return false;
}
var year = $('#bookYear').val();
if (year == "") {
$('.error').show();
return false;
}
var place = $('#bookPlace').val();
if (place == "") {
$('.error').show();
return false;
}
var publisher = $('#bookPublisher').val();
if (publisher == "") {
$('.error').show();
return false;
}
var edition = $('#bookEdition').val();
var page = $('#bookPage').val();
var completeString1 = authorname + ' ' + '(' + year + '),' + ' ' + '<i>' + booktitle + '</i>' + ', ' + edition + ' ed., ' + place + ': ' + publisher + ', ' + page;
$('.error').hide();
$('#output').empty();
$('#output').append(completeString1);
});
As you see, I have 5 variables that have to be filled out, and 2 that don’t. I create the entire string in completeString1, where I also put in the commas and so on. I know this is probably not the easiest way to do, but it is how I could do it. My problem now, is that my completeString1 will still contain and print “ed.,” even if I don’t fill out the variable.
So my question is: How can I leave out that bit of the variable, given that it is not filled out?
What I got is that you have problem with “edition” variable. So you need to change the way you assign the value to it:
And then, update
completeString1setting to: