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
Post a Comment