This probably isn't very complicated but I'm not a coder by trade so I'm sure I am missing something here.
Here is what I have so far.
function buildURL (){
url = document.getElementById("url").value;
source = document.getElementById("source").value; //required
campaignId = '-_-' + document.getElementById("campid").value; //required
brand = '-_-' + document.getElementById("brand").value; //required
brand2 = '-' + document.getElementById("brand2").value; //optional
brand3 = '-' + document.getElementById("brand3").value; //optional
medium = '-_-' + document.getElementById("medium").value; //required
product = '&cm_mmca1=" + document.getElementById("product").value; //optional
if (url.includes('?')) {
url = url + '&cm_mcc=';
} else {
url = url + '?cm_mmc=';
}
document.getElementById("fullURL").innerHTML = "URL: " + url + source + campaignId + brand + brand2 + brand3 + medium + product ;
}
Now, the url part works great. It prints to screen as soon as I enter a URL in a text box in a form I created and it updates as I make changes. The problem comes with the additional values I print to screen. Everything that proceeds each variable's document.getElementById
prints to the screen immediately. This is fine for the required variables but not the optional variables. I'm thinking the solution is to prevent all fields from being passed to document.getElementById("fullURL").innerHTML
unless there is a value in the field but I am not sure how to do that. Suggestions?