Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
how can this html code be modified to allow a user to input the number of format rows present on a webpage?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>

<form>
  num: <input type="number" name="a" id="num"><br>
 <button onclick="addnewrow()">Add</button>
</form>
function addnewrow(num) {
  var num   = document.getElementById('num').value
  var count = 1

  for (i = 0; i <=num; i++)
    {
    var newrow = '<div class="row">'
               + '<div class="col-md-4">'
               + '<div class="form-group label-floating">'
               + '<label class="control-label">Title + count</label>'
               + '<input type="text" class="form-control" v-model="act" >'
               + '</div>'
               + '</div>'
               + '</div>';
    count++:
    return newrow;
    }
}

This html code is supposed to take in an input number in the first form the output that number of form rows, however this doesn't work how can this be amended for it to work

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  • I am selecting button using document.querySelector("#add").
  • After that I am attaching click event on it.
  • e.preventDefault() to stop default behavior of form for submitting.
  • Than I am taking number value converting it to integer from string input and running for-loop.
  • I am not validating user input here.
  • And lastly, appending row in selected main div using innerHTML.

const main = document.querySelector("#main");

const addButton = document.querySelector("#add");
addButton.addEventListener("click", (e) => {
  e.preventDefault();
  var num = parseInt(document.getElementById('num').value);
  for (i = 1; i <= num; i++) {
    main.innerHTML += `<div class="row"><div class="col-md-4"><div class="form-group label-floating"><label class="control-label">Title + count</label><input type="text" class="form-control" v-model="act"></div></div></div>`
  }
});
'<div class="row">'+'<div class="col-md-4">'+'<div class="form-group label-floating">'+'<label class="control-label">Title + count</label>'+'<input type="text" class="form-control" v-model="act" >'+'</div>'+'</div>'+'</div>';
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<form>
  num: <input type="number" name="a" id="num"><br>
  <button id="add">Add</button>
  <div id="main"></div>
</form>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!