0

I have multiline string in javascript. I have input element the value of which is set to, value fetched from file.

What I am not able to do is to set the value of this input element to value of this variable.

let port="";
let xmlData = fs.readFileSync(xmlFileRW,function(err,data){port=data;});

let xmlFileData = `
    <form> 
    <tr>
      <th class="hostid-th-padding">
        <b>PORT</b>
      </th>
      <td class="hostid-td-padding">
        <input id="port" type="text" size="7" value=""+port+"" onkeypress="buttonEnable()"></input>
      </td>
    </tr>
karansys
  • 2,449
  • 7
  • 40
  • 78

1 Answers1

1

let port="";
let xmlData = fs.readFileSync(xmlFileRW,function(err,data){port=data;});

let xmlFileData = `
    <form> 
    <tr>
      <th class="hostid-th-padding">
        <b>${port}</b>
      </th>
      <td class="hostid-td-padding">
        <input id="port" type="text" size="7" value="${port}" onkeypress="buttonEnable()"></input>
      </td>
    </tr>
`
VLAZ
  • 26,331
  • 9
  • 49
  • 67
folo
  • 476
  • 4
  • 5
  • Hi VLAZ, it works but if the file doesn't exist at all then port value is empty, I see in the input box "onkeypress="buttonEnable()" – karansys Jun 21 '19 at 13:44
  • 1
    @karansys `port = data || ""` to set a default value of an empty string. – Ace Jun 21 '19 at 13:46