Javascript - How to use variable when writing table

Viewed 583

I'm trying to print the value of a variable in the first column of my table, but when I run the method, I get the name of the variable instead

I have the following code

function writeTable() {
  var table;
  var uInput = document.test.input.value;
  table = "<table><tr><th colspan=3>Table Header</th></tr>";
  table += "<tr><th>Column1</th><th>column2</th><th>column3</th></tr>";
  table += '<tr><td>uInput</td><td>Value2</td><td>value3</td></tr>';
  document.write(table);
}
<form name="test">
  <input type="text" name="input">
</form>
<input type="submit" name="submit" value="Write Table" onclick="writeTable()">

4 Answers
Related