I have the following function below and it works great when all 3 vars are not null, however, how can it be modified such that when either variable (tel, fax, cell) are null, that the line containing the null variable does not get written?
Current scenario:
T. 123-4567-8910
F. 987-654-3210
C.
-------------------------------
Desired scenario:
T. 123-4567-8910
F. 987-654-3210
-------------------------------
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function test() {
var tel = "123-4567-8910"
var fax = "987-654-3210"
var cell = ""
var html =
'<div>T. '+ tel +'</div>\n' +
'<div>F. '+ fax +'</div>\n' +
'<div>C. '+ cell +'</div>'
document.write(html)
}
</script>
</head>
<body>
<a href="javascript:test()">test</a>
</body>
</html>
Let me introduce you to conditional statements:
Although
document.write()is usually considered a bad idea. You can read more about it here.