Connect javascript and HTML -


i'm beginning learn javascript , , browser api. why, if press "save" button , pop window not appears in browser ? wrong?

<label for="txtnome"><input id="txtnome" type="text" value=""/><br/></label> <label for="txtcognome"><input id="txtcognome" type="text" value=""/><br/></label> <button id="btnsalva"/>salva</button><br/>  <script>     var model = { nome: "mario", cognome: "rossi" };      var view = {         txtnome: document.getelementbyid("txtnome"),         txtcognome: document.getelementbyid("txtcognome"),         btnsalva: document.getelementbyid("btnsalva")     };      var controller;         controller = {          init: function () {             view.txtnome.value = model.nome;             view.txtcognome.value = model.cognome;             view.btnsalva.onclick = controller.salva;         },          salva: function () {             model.nome = view.txtnome.value;             model.cognome = view.txtcognome.value;             window.alert("fatto");         }     }; </script> 

you need call controller.init(), otherwise code nothing, declaring objects.

var model = { nome: "mario", cognome: "rossi" };    var view = {    txtnome: document.getelementbyid("txtnome"),    txtcognome: document.getelementbyid("txtcognome"),    btnsalva: document.getelementbyid("btnsalva")  };    var controller;  controller = {      init: function () {      view.txtnome.value = model.nome;      view.txtcognome.value = model.cognome;      view.btnsalva.onclick = controller.salva;    },      salva: function () {      model.nome = view.txtnome.value;      model.cognome = view.txtcognome.value;      window.alert("fatto");    }  };    controller.init(); //call init!
<label for="txtnome"><input id="txtnome" type="text" value=""/><br/></label>  <label for="txtcognome"><input id="txtcognome" type="text" value=""/><br/></label>  <button id="btnsalva"/>salva</button><br/>


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -