0
I have a little problem I’d like some ideas to solve:
I have an order screen, where I select the product in a combo, enter the quantity and when I click a button, I want to enter the combo value data and the value of the quantity in some javascript array, display in a table just below and insert this data into a php array so that when you save the request, you can scan this array in php and save the data to the database.
There’s a way to make it simple?
Supplementing the question:
I currently use jQuery libraries and my system is done in Codeigniter. The PHP Array I would keep in the view itself and pass as parameter to the Controller when saving everything in the database.
Currently I use an Ajax to fetch the price of the bank’s product without giving the refresh, so the part of looking for data from the bank with ajax I can already turn around, as I show below:
<script type="text/javascript">
$(document).ready(function () {
$("select[name='produto_id']").change(function () {
var base_url = '<?php echo base_url();?>';
alert('Entrou');
var preco = $("input[name='valor']");
//var teste = $("select[name='nome']").val();
//alert(teste);
$(preco).val('Carregando...');
$.ajax({
type: "POST",
//url: "application/views/admin/teste.php",
url: '<?php echo base_url(); ?>index.php?admin/list_dropdown',
data: "prod=" + $("select[name='produto_id']").val(),
success: function (json) {
alert(json);
//$(preco).val((Math.round(json * 100) / 100)).toFixed(2);
$(preco).val(json).toFixed(2);
}
});
//);
});
});
</script>
My question would be, how to take this javascript data, add it in a PHP array (because I don’t know how many products will be selected) and then, when clicking the save button, I send this array together to the controller.
Hugging!
Post the combo part and the order screen, which makes it easier to help you pass the array you already have to PHP. It is not complicated, but it is convenient to leave already as far as it was published with the question.
– Bacco
Ariel, complete your question with more code and clarity about what you want (as Bacco asked). Also clarify if the PHP file is the same as the file where tm HTML and if you use some Javascript library like Mootools or jQuery.
– Sergio
Additionally, see if this is the answer you’re looking for. If it is, you can even delete the question, if it isn’t, give more details. http://answall.com/questions/8106/array-em-javascript-que-se-comunique-em-php
– Bacco
Guys, I updated my question, I think it’s clearer now...
– Ariel Lobe