0
I’m trying to popular a type["text"] through jquery and it’s not working!
Form:
<div>
<label>Plano:</label>
<select name="plano" id="plano" required>
<?php echo $stringPlanos; ?>
</select> <br /><br />
</div>
<div style="float:left">
<label class="labelPequeno">Valor</label><input type="text" class="real" style="width:100px; height:40px" required maxlength="23" id="valorCombinado" name="valorCombinado" /> <br /><br />
</div>
Jquery code
<!-- INICIO ENTREGA VALOR DO PLANO -->
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
$(function(){
$('#plano').change(function(){
if( $(this).val() ) {
$.getJSON('planos.ajax.php?search=',{cod_plano: $(this).val(), ajax: 'true'}, function(resultado){
var resultado = planosRetorno;
alert(resultado);
$('#valorCombinado').val(resultado).show();
});
} else {
$('#valorCombinado').val('0.00');
}
});
});
</script>
<!-- FIM ENTREGA VALOR DO PLANO -->
ajax.php plans
<?php
$cod_plano = mysql_real_escape_string( $_REQUEST['cod_plano'] );
$planosBase = $PlanosDao->pesquisaPlanoEdicao($cod_plano);
$planosRetorno = $planosBase->getValor();
echo( json_encode($planosRetorno) );
?>
But, the browser console shows no$ errors and the field is not populated!
Where am I going wrong?
If what you want popular is a
input
you have to use.val(resultado)
and not.html(resultado)
. Is that the problem?– Sergio
$('#valueCombined'). val(result). show();??? Didn’t work. But I guess not. Because even Alert doesn’t work!
– Carlos Rocha
Test this code: http://jsfiddle.net/e3jdemdb/
– Sergio
Don’t go changing the question please... leave it as it was, even if it was wrong. It may be useful for others.
– Sergio
Sérgio. It didn’t work. Neither did Alert work! But remember I’m using the jquery autocomplete plugin.Want me to add his call to the question?
– Carlos Rocha
Usa
echo json_encode($planosRetorno);
unrelated here:echo()
.– Sergio
When you use this code I put in jsFiddle what gives you in ajax headers?
– Sergio
not so Sérgio. headers from Ajax? How do I see this?
– Carlos Rocha
Let’s go continue this discussion in chat.
– Sergio
What happens is that these select values are changed not in select, but in a dynamically created lis UL. In that case, I will have to figure out how to get the value of the selected li! Will have to?
– Carlos Rocha