With the help of the comunity (Thanks all of you !) I manage to create 3 fields at a time in a single row, anytime the user needs it. The thing is that everytime it create the fields, the placeholder is always "Another field". I would like that instead of that says Infrastracture, Time, Monthly Cost", but I have no clue how to do that.
Thank you Kindly !
Html Code:
<!doctype html>
<html>
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<!-- Awsome Fonts-->
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Styling -->
<link rel="stylesheet" type="text/css" href="style.css">
<!-- My Title-->
<title>Hello, world!</title>
</head>
<body>
<form class="Form" id="formulario">
<h1>Factibilidad Técnica y Operativa</h1>
<h2>Análisis de Infraestructura</h2>
<!-- Campos en Columnas-->
<div class="container" id="contenedor">
<div class="row" id="campo">
<div class="col-lg-4 mb-2">
<input type="text" class="form-control" placeholder="Infraestructura">
</div>
<div class="col-lg-4 mb-2">
<input type="text" class="form-control" placeholder="Tiempo">
</div>
<div class="col-lg-4 mb-2">
<input type="text" class="form-control" placeholder="Costo Mensual">
</div>
</div>
</div>
<!-- Iconos de Agregar / Eliminar Campos-->
<div class="Controls">
<a href="#" id="add_more_fields" onclick="createTwoInput()"><i class="fa fa-plus-square"></i>Añadir</a>
<a href="#" id="removefields" onclick="Eliminar()"><i class="fa fa-minus-square"></i>Eliminar</a>
</div>
</form>
<!-- JS Script-->
<script src="script.js"></script>
</body>
</html>
JavaScript Code:
var survey_options = document.getElementById('campo');
var add_more_fields = document.getElementById('add_more_fields');
var remove_fields = document.getElementById('remove_fields');
function Añadir(){
var newDiv = document.createElement('div');
newDiv.setAttribute('class', 'col-lg-4 mb-2')
var newField = document.createElement('input');
newField.setAttribute('type','text');
newField.setAttribute('class','form-control');
newField.setAttribute('placeholder','Another Field');
survey_options.appendChild(newDiv);
newDiv.appendChild(newField);
}
function createTwoInput(){
Añadir();
Añadir();
Añadir();
}
function Eliminar(){
var input_tags = survey_options.getElementsByTagName('input');
if(input_tags.length > 2) {
survey_options.removeChild(input_tags[(input_tags.length) - 1]);
}
}