Bala Vignesh C S Bala Vignesh C S - 1 year ago 46
HTML Question

I'm trying to add textboxes within ordered list onclick of a button using JavaScript and also increment ID name while adding the textbox

I tried using document.createElement, which works fine to add textbox but I can't increment ID name.
I am using it in a metro app.

Answer Source
  No. of lines:
  <input type="text" id="number" value="0" width=20px/>
  <input type="button" onclick="incrementValue()" value="Add Line" />
  <ol id="linedata">

function incrementValue() {
  var value = parseInt(document.getElementById('number').value, 10);
  value = isNaN(value) ? 0 : value;
  document.getElementById('number').value = value;
  var list = document.createElement('li');
  var box = document.createElement('input');
  box.type = 'text'; = 'line' + value;
  box.placeholder='Line ' + value;