I am using a regular replace call, but I want it to also replace the whole part of the text with blank/empty space if nothing is entered in the input(data) area. Here is the code and jsfiddle example: https://jsfiddle.net/6rhfdmfa/
Here is the div with input areas from which it gets the data:
<div id="wrap">
<div id="inputmeasurements">
<p id="topmeasurement" align=left>
<input type="text" class="topm" id="title" name="title" maxlength="80" placeholder="TITLE"><span id="counter"></span>
<br>
<input type="text" class="topm" id="specifics" name="specifics" placeholder="Specifics">
<br>
<input type="text" class="topm" id="supplier" name="supplier" placeholder="Supplier">
<br>
<input type="text" class="topm" id="date" name="date" placeholder="Date">
<br>
<input type="text" class="topm" id="weight" name="weight" placeholder="Weight">
<br>
<textarea class="topm" id="mercedes" placeholder="Enter Any Aditional Data Here"></textarea>
<br>
<br>
</p>
<p id="botmeasurement">
<input type="text" class="botm" id="bust" name="bust"> Bust
<br>
<input type="text" class="botm" id="waist" name="waist"> Waist
<br>
<input type="text" class="botm" id="hips" name="hips"> Hips
<br>
<input type="text" class="botm" id="lng" name="lenght"> Lenght
<br>
<input type="text" class="botm" id="shl" name="shoulders"> Shoulders
<br>
<input type="text" class="botm" id="slv" name="sleeves"> Sleeves
<br>
<input type="text" class="botm" id="ins" name="inseam"> Inseam
<br>
</p>
<div id="enter-meta-wrap">
<p style="text-align: center;">Convert data to html ready metadata:</p>
<button id="enter-meta" onclick="myFunction2();switchVisible();">Convert</button>
</div>
</div>
This is where it will get entered:
<div id="finishedmeasurements" style="display:none;">
<table id="grid" cellspacing="0" cellpadding="0">
<tr onclick="clipboard(this);">
<td>
<p id="m1" align=center>TITLE</br>
<br>SPECIFICS</br>
<br>SUPPLIER | DATE | WT WEIGHT</br>
<br>MERC</br>
<br>
<br>B1 Bust inches flat</br>
<br>W1 Waist inches flat</br>
<br>H1 Hips inches flat</br>
<br>L1 Length </br>
<br>S1 Shoulders </br>
<br>S2 Sleeves </br>
<br>I1 Inseam </br>
<br>
</p>
</td>
</tr>
</table>
<div id="new-meta-wrap">
<p style="text-align: center;">Convert new data:</p>
<button id="new-meta" onclick="myFunction3()">New</button>
</div>
</div>
Current replace call:
//Convert input into formated metadata
function myFunction2() {
var str = document.getElementById("m1").innerHTML;
var res = str.replace(/B1/g, document.getElementById("bust").value).replace(/W1/g, document.getElementById("waist").value).replace(/H1/g, document.getElementById("hips").value).replace(/L1/g,document.getElementById("lng").value)
.replace(/S1/g, document.getElementById("shl").value).replace(/S2/g, document.getElementById("slv").value).replace(/I1/g, document.getElementById("ins").value)
.replace("TITLE", document.getElementById("title").value).replace("SPECIFICS", document.getElementById("specifics").value).replace("MERC", document.getElementById("mercedes").value)
.replace("SUPPLIER", document.getElementById("supplier").value).replace("DATE", document.getElementById("date").value).replace("WEIGHT", document.getElementById("weight").value);
document.getElementById("m1").innerHTML = res;
}