I need to add the text type input with the checkbox type input, at this moment when I click on the checkbox it adds up and shows the total, but I need to add the text type input called service price.
This is a screenshot of my form:
This is my code:
<?php foreach($servicelist as $listsv): ?>
<input name="service[]" type="checkbox" onClick="if (this.checked) sumar(<?php echo $listsv["price"]; ?>); else restar(<?php echo $listsv["price"]; ?>)" value='<?php echo $listsv["id"]; ?>'><?php echo utf8_encode($listsv['service']); ?><br>
<?php endforeach; ?>
<br>
This is my function
var total = 0;
function sumar(valor) {
total += valor;
document.formulario.total.value = '$' + total.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
}
function restar(valor) {
total -= valor;
document.formulario.total.value = '$' + total.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
}
function otro_servicio() {
$("#lineas").append('<label>Nombre Servicio</label>');
$("#lineas").append('<input name="othersv" type="text" class="form-control importe_linea" placeholder="Nombre del servicio extra"/><br/>');
$("#lineas").append('<label>Precio Servicio</label>');
$("#lineas").append('<input name="price" type="text" class="form-control importe_linea" placeholder="Precio del servicio"/><br/>');
}
To achieve this goal I can use javascript, jquery or angular.