I'm trying to make a button on an HTML form add elements to the form:
function createRow(){
var row = document.createElement('div');
var input=document.createElement('input');
input.setAttribute("type", "Textbox");
var time=document.createElement('input');
time.setAttribute("type", "Textbox");
row.appendChild(input);
row.appendChild(time);
return row;
}
function addRow(){
console.log("z");
var routes = document.getElementById("routes");
routes.appendChild(createRow());
return false;
}
<form id="routes">
<button onclick="addRow()">+</button>
</form>
But on each button click the page reloads with a question mark added to url. I've found a pair of ideas:
- preventDefault(e)
- return false
but none worked.
Please tell me what shall I fix? Also there are some conditions:
- This is not the submit button, which will be added later
- It's required to keep it as simple as possible, the interface is not main focus of project