lundi 22 février 2016

Jquery: why .val() isn't changing the output when setting something inside as a parameter?

I'm trying to replace some form input box into a text after clicking a button. So, what's inside the #horario09 div, should be replaced by "La reserva es para: '+nombre" where nombre is whatever you've inserted into the text input.

<form id="form1" action="">
        Horario: 09 horas <input type="text" id="h09">
        <button class="btn btn-primary" onclick="return reservas.guardarReserva();">Reservar</button>
        <div id="#horario09"></div>
</form> 

var reservasAPP = {
    guardarReserva:function(){
        var nombre = $('#h09').val();
        var reservaConfirmada = $('#horario09').val('La reserva es para: '+nombre);
        console.log(nombre);
        console.log(reservaConfirmada);
        return false;
    }
}
window.reservas = reservasAPP;

I'm inserting some console.log() in order to test, and nombre gets printed ok. Why .val() isn't replacing the div's content? I've read the documentation and it seems that it should change the value when I set something as a paratemer of val().

Console.log of reservaConfirmada gets me this output: [context: document, selector: "#horario09"]

Aucun commentaire:

Enregistrer un commentaire