I'm doing a system related to recycled material. I pay to the person who brings the material, and there are 12 kinds of recycled material.
I need to shrink the functions of the buttons to be more friendly.
This is my modal
<div
class="modal fade bd-example-modal-lg"
id="modalCRUD"
tabindex="-1"
role="dialog"
aria-labelledby="exampleModalLabel"
aria-hidden="true"
>
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"></h5>
<button
type="button"
class="close"
data-dismiss="modal"
aria-label="Close"
>
<span aria-hidden="true">×</span>
</button>
</div>
<form id="formUsuarios">
<div class="modal-body">
<div id="s">
<div class="row">
<div class="col">
<div class="form-group">
<label for="" class="col-form-label"
>Nombres</label
>
<input
type="text"
class="form-control"
id="nombre"
readonly
/>
</div>
</div>
<div class="col">
<div class="form-group">
<label for="" class="col-form-label"
>Apellidos</label
>
<input
type="text"
class="form-control"
id="apellido"
readonly
/>
</div>
</div>
<div class="col">
<div class="form-group">
<label for="" class="col-form-label"
>DNI</label
>
<input
type="number"
class="form-control"
id="dni"
readonly
/>
</div>
</div>
<div class="col">
<div class="form-group">
<label for="" class="col-form-label"
>Saldo</label
>
<input
type="number"
class="form-control"
id="saldo"
step="any"
readonly
/>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="form-group">
<button
type="button"
class="botonimagen1"
onclick="myFunction1()"
></button>
<button
type="button"
class="botonimagen1"
onclick="myFunction2()"
></button>
<button
type="button"
class="botonimagen1"
onclick="myFunction3()"
></button>
<button
type="button"
class="botonimagen1"
onclick="myFunction4()"
></button>
<button
type="button"
class="botonimagen1"
onclick="myFunction5()"
></button>
<button
type="button"
class="botonimagen1"
onclick="myFunction6()"
></button>
<button
type="button"
class="botonimagen1"
onclick="myFunction7()"
></button>
<button
type="button"
class="botonimagen1"
onclick="myFunction8()"
></button>
<button
type="button"
class="botonimagen1"
onclick="myFunction9()"
></button>
<button
type="button"
class="botonimagen1"
onclick="myFunction10()"
></button>
<button
type="button"
class="botonimagen1"
onclick="myFunction11()"
></button>
<button
type="button"
class="botonimagen1"
onclick="myFunction12()"
></button>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="form-group">
<input
type="text"
class="form-control"
id="material1"
readonly
/>
</div>
</div>
<div class="col">
<div class="form-group">
<input
type="text"
class="form-control"
id="precio1"
readonly
/>
</div>
</div>
<div class="col">
<div class="form-group">
<input
type="number"
class="form-control"
step="any"
oninput="subtotal1a()"
id="peso1"
readonly
/>
</div>
</div>
<div class="col">
<div class="form-group">
<div class="input-icon input-icon-right">
<input
type="number"
class="form-control"
value="0"
oninput="sumar()"
id="subtotal1"
readonly
/>
<i>CC</i>
</div>
</div>
</div>
<div class="col">
<div class="form-group">
<input
type="number"
class="form-control"
id="quitar1"
readonly
/>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="form-group">
<input
type="text"
class="form-control"
id="material2"
readonly
/>
</div>
</div>
<div class="col">
<div class="form-group">
<input
type="text"
class="form-control"
id="precio2"
readonly
/>
</div>
</div>
<div class="col">
<div class="form-group">
<input
type="number"
class="form-control"
step="any"
oninput="subtotal2a()"
id="peso2"
readonly
/>
</div>
</div>
<div class="col">
<div class="form-group">
<div class="input-icon input-icon-right">
<input
type="number"
class="form-control"
value="0"
oninput="sumar()"
id="subtotal2"
readonly
/>
<i>CC</i>
</div>
</div>
</div>
<div class="col">
<div class="form-group">
<input
type="number"
class="form-control"
id="quitar2"
readonly
/>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="form-group">
<input
type="text"
class="form-control"
id="material3"
readonly
/>
</div>
</div>
<div class="col">
<div class="form-group">
<input
type="text"
class="form-control"
id="precio3"
readonly
/>
</div>
</div>
<div class="col">
<div class="form-group">
<input
type="number"
class="form-control"
step="any"
oninput="subtotal3a()"
id="peso3"
readonly
/>
</div>
</div>
<div class="col">
<div class="form-group">
<div class="input-icon input-icon-right">
<input
type="number"
class="form-control"
value="0"
oninput="sumar()"
id="subtotal3"
readonly
/>
<i>CC</i>
</div>
</div>
</div>
<div class="col">
<div class="form-group">
<input
type="number"
class="form-control"
id="quitar3"
readonly
/>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="form-group">
<div class="input-icon input-icon-right">
<input
type="number"
class="form-control"
placeholder="0"
id="carga"
name="carga"
min="0"
step="any"
style="
font-size: 40px;
text-align: center;
"
size="13"
title="Currency"
pattern="^\d+(?:\.\d{1,2})?$"
/>
<i>CC</i>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button
type="button"
class="btn btn-light"
data-dismiss="modal"
>
Cancelar
</button>
<button type="submit" id="btnGuardar" class="btn btn-dark">
Guardar
</button>
</div>
</form>
</div>
</div>
</div>
this is my script
<script>
function myFunction1() {
if (document.getElementById("material1").value == "") {
document.getElementById("material1").value = "1 PET";
document.getElementById("precio1").value = 1.5;
document.getElementById('peso1').readOnly = false;
document.getElementById("peso1").focus();
} else if (document.getElementById("material2").value == "") {
document.getElementById("material2").value = "1 PET";
document.getElementById("precio2").value = 1.5;
document.getElementById('peso2').readOnly = false;
document.getElementById("peso2").focus();
} else if (document.getElementById("material3").value == "") {
document.getElementById("material3").value = "1 PET";
document.getElementById("precio3").value = 1.5;
document.getElementById('peso3').readOnly = false;
document.getElementById("peso3").focus();
} else {
document.getElementById("material4").value = "1 PET";
document.getElementById("precio4").value = 1.5;
document.getElementById('peso4').readOnly = false;
document.getElementById("peso4").focus();
}
};
function myFunction2() {
if (document.getElementById("material1").value == "") {
document.getElementById("material1").value = "2 PEAD";
document.getElementById("precio1").value = 2.0;
document.getElementById('peso1').readOnly = false;
document.getElementById("peso1").focus();
} else if (document.getElementById("material2").value == "") {
document.getElementById("material2").value = "2 PEAD";
document.getElementById("precio2").value = 2.0;
document.getElementById('peso2').readOnly = false;
document.getElementById("peso2").focus();
} else if (document.getElementById("material3").value == "") {
document.getElementById("material3").value = "2 PEAD";
document.getElementById("precio3").value = 2.0;
document.getElementById('peso3').readOnly = false;
document.getElementById("peso3").focus();
} else {
document.getElementById("material4").value = "2 PEAD";
document.getElementById("precio4").value = 2.0;
document.getElementById('peso4').readOnly = false;
document.getElementById("peso4").focus();
}
};
function myFunction3() {
if (document.getElementById("material1").value == "") {
document.getElementById("material1").value = "3 PVC";
document.getElementById("precio1").value = 1.0;
document.getElementById('peso1').readOnly = false;
document.getElementById("peso1").focus();
} else if (document.getElementById("material2").value == "") {
document.getElementById("material2").value = "3 PVC";
document.getElementById("precio2").value = 1.0;
document.getElementById('peso2').readOnly = false;
document.getElementById("peso2").focus();
} else if (document.getElementById("material3").value == "") {
document.getElementById("material3").value = "3 PVC";
document.getElementById("precio3").value = 1.0;
document.getElementById('peso3').readOnly = false;
document.getElementById("peso3").focus();
} else {
document.getElementById("material4").value = "23 PVC";
document.getElementById("precio4").value = 1.0;
document.getElementById('peso4').readOnly = false;
document.getElementById("peso4").focus();
}
};
Screenshot: Modal
I only showed programing 3 of 12 products. How can I minimize the functions of the buttons? I have to repeat for every row, but how can I add a row every time programatically?