-1
I wonder how I could turn my dynamic form’s Divs into input text value when it is clicked on Submit .
My form
<div class="container">
<h1 class="restaurant-title">Peixaria</h1>
<div id="menu-panel" class="col-sm-12 paddingselect">
<?php
categoriaas();
?>
</div>
<div id="menu-panel-2">
</div>
<div id="caja-panel">
<div class="well">
<form method="post" action="relatorio.php" id="formRel">
<!-- left -->
<div id="theproducts" class="col-sm-5">
</div>
<!-- left -->
<span>Mesa:</span>
<input type="text" name="mesa"value="">
<input type="text" id="theinputsum">
<!-- right -->
<div id="thetotal" class="col-sm-7">
<h1 id="total"></h1>
<button class="btn btn-lg btn-success btn-block"><i type="submit" class="fa fa-shopping-cart" aria-hidden="true"></i> Finalizar Pedido</button>
</div>
<!-- right -->
</form>
</div>
</div>
</div>
<!-- container -->
<script>
$('#formRel').submit(function(event){
event.preventDefault();
var formDados = new FormData($(this)[0]);
$.ajax({
method: "POST",
url: "relatorio.php",
data: $("#formRel").serialize(),
dataType : "html"
});
};
</script>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<!-- Restaurant -->
<script src="js/
Restaurant.js">
My javascript code that makes the form dynamic
$('.restaurantcatbtn').on('click', function(){
var attrcat = $(this).attr('data-categoria');
var datacat = 'categoria='+attrcat;
$.ajax({
type: 'POST',
url: 'includes/processfunction.php',
data: datacat,
beforeSend: function(){
$('#menu-panel-2').append('<div class="cssload-thecube"><div class="cssload-cube cssload-c1"></div><div class="cssload-cube cssload-c2"></div><div class="cssload-cube cssload-c4"></div><div class="cssload-cube cssload-c3"></div></div>');
},
success: function(data){
$('#menu-panel-2').html(data);
},
error: function(){
}
});
});
function agregarcaja(producto){
var addproducto = $('#theproductitem'+producto).attr('data-nombre');
var dataprocutstock = $('#theproductitem'+producto).attr('data-stock');
var dataprocutprecio = $('#theproductitem'+producto).attr('data-precio');
var addproductodiv = $('#cajaitem'+producto);
var theinputsum = $('#theinputsum');
if ($(addproductodiv).length)
{
return;
}else{
if (theinputsum.val() == ''){
theinputsum.val(dataprocutprecio);
$('#total').text('Total a pagar: $'+dataprocutprecio);
}else{
var lastthevalue = theinputsum.val();
var thenextvalue = parseFloat(lastthevalue) + parseFloat(dataprocutprecio);
theinputsum.val(thenextvalue);
$('#total').text('Total a pagar: $'+thenextvalue);
}
$('#theproducts').append('<span id="cajaitem'+producto+'" data-precio="'+dataprocutprecio+'" data-cantidad="1" class="btn btn-block btn-sm">'+addproducto+' [$'+dataprocutprecio+'] <p id="thepitemcantidad'+producto+'" class="pull-right cantidad-item-p">1</p> <button style="margin-left:4px;" onclick="cantidadProductoPlus('+producto+')" class="btn btn-xs btn-success pull-right"><i class="fa fa-plus-square" aria-hidden="true"></i></button> <button class="btn btn-xs btn-danger pull-right"><i class="fa fa-minus-square" onclick="cantidadProductoMinus('+producto+')" aria-hidden="true"></i></button> </span>');
}
}
function cantidadProductoMinus(producto){
var cantidad = $('#cajaiteminput'+producto).val();
var precio = $('#cajaitem'+producto).attr('data-precio');
var cantidaditem = $('#cajaitem'+producto).attr('data-cantidad');
var theinputsum = $('#theinputsum').val();
var theinputsumelement = $('#theinputsum');
if (cantidaditem == 1){
var thedeleteitem = parseFloat(theinputsum) - parseFloat(precio);
theinputsumelement.val(thedeleteitem);
if (thedeleteitem == 0){
$('#total').text('');
}else{
$('#total').text('Total a pagar: $'+thedeleteitem);
}
$('#cajaitem'+producto).remove();
}else{
var thefinalcantidad = parseInt(cantidaditem) - 1;
var thedeleteitem = parseFloat(theinputsum) - parseFloat(precio);
theinputsumelement.val(thedeleteitem);
$('#thepitemcantidad'+producto).text(thefinalcantidad);
$('#cajaitem'+producto).attr('data-cantidad', thefinalcantidad);
var minusprice = parseFloat(theinputsum) - parseFloat(precio);
$('#theinputsum').val(minusprice);
$('#total').text('Total a pagar: $'+minusprice);
}
}
function cantidadProductoPlus(producto){
var cantidaditem = $('#cajaitem'+producto).attr('data-cantidad');
var precio = $('#cajaitem'+producto).attr('data-precio');
var theinputsum = $('#theinputsum').val();
var sumprice = parseFloat(theinputsum) + parseFloat(precio);
var thefinalcantidad = parseInt(cantidaditem) + 1;
$('#thepitemcantidad'+producto).text(thefinalcantidad);
$('#cajaitem'+producto).attr('data-cantidad', thefinalcantidad);
$('#theinputsum').val(sumprice);
$('#total').text('Total a pagar: $'+sumprice);
}
Wouldn’t it be simpler to create these Divs as disabled inputs? Why would it be enough to change the value of the disabled attribute, it would be simpler and the code would be cleaner. To change the way you are asking it would be necessary to destroy your form with Jquery and rewrite it as you need it
– Rúbio Falcão
@Rúbiofalcão how could I do that ? type the categories are the ones that come from the database . I just make select the orders and give Submit .
– allan araujo
You can add the attribute
contenteditable="true"
in the desired div it can be edited. There you treat the propertyinnerHTML
and not thevalue
. That’s how Angouts chat works =)– Oeslei