Put your string formatting code in a function where you can use if statements.
document.getElementById("target").value = formatValue();
function formatValue(){
var formattedString = Constant;
if(name){
formattedString += " " + name;
}
if(age){
formattedString += " " + age:
}
if(height){
formattedString += " " + height:
}
return formattedString;
}
If you prefer not to have a named function, use a self-invoking anonymous function:
document.getElementById("target").value = (function(){
var formattedString = Constant;
if(name){
formattedString += " " + name;
}
if(age){
formattedString += " " + age:
}
if(height){
formattedString += " " + height:
}
return formattedString;
})();
ifstatement inside an expression. You are looking for the conditional operator.