Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving variable if not filled out
    primarykey
    data
    text
    <p>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:</p> <pre><code> $('#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 + '&amp;nbsp;' + '(' + year + '),' + '&amp;nbsp;' + '&lt;i&gt;' + booktitle + '&lt;/i&gt;' + ',&amp;nbsp;' + edition + '&amp;nbsp;ed.,&amp;nbsp;' + place + ':&amp;nbsp;' + publisher + ',&amp;nbsp;' + page; $('.error').hide(); $('#output').empty(); $('#output').append(completeString1); }); </code></pre> <p>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.</p> <p>So my question is: How can I leave out that bit of the variable, given that it is not filled out?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload