0
I want to load a value into an input text after selecting a value in a select. I am loading the normal select. I want to load input text using javascript. In my model I compare it with id. The data is in the same table.
Java Script:
<script>
var base_url = '<? echo base_url() ?>';
function busca_produtos(id_alug){
$.post(base_url+"parcelas/get_parcelas", {
id_alug : id_alug
}, function(data){
$('#parcelas').html(data);
});
}</script>
My normal working select input:
echo "<select name='aquiller' id='id' class='form-control input-sm' onchange='busca_produtos($(this).val())'>";
My Controller:
public function get_parcelas(){
$parcelas = $this->sindico->get_parcelas();
$option = "<option value=''></option>";
foreach($parcelas -> result() as $linha) {
$option .= "<option value='$linha->id_alug'>$linha->id</option>";
}
echo $option;
}
@Magichat bro you can give a little pull in this problem?
– Ramon Chaves
Ramon do you want when a select value is selected that value to be placed in an input text is that? Or it would fetch another value based on the value of select?
– fernandoandrade
It would fetch another value based on the value of select. You’ve seen my code. Can you tell me where I can get.
– Ramon Chaves
is giving this message: Message: Invalid argument supplied for foreach()
– Ramon Chaves
The variable $parcels -> result() is a valid array? can that be
– fernandoandrade
@Ramonchaves I believe the comment above may be the point in question, foreach works with arrays, and result() seems to me a method.
– MagicHat