Friday, 15 July 2011

javascript - Clear textbox without refreshing the page -



javascript - Clear textbox without refreshing the page -

i want textbox clear cache whenever user save data. want dialog in page clear (reset) info without need refresh page.

i tried set code in javascript

_self.somevaluehere("");

and tried set code in html.

onfocus="if(this.value=='a new value') this.value='';

still won't work.

here piece of html code:

<p> <label data-bind="text: key"></label><br/> <input type="text" data-bind="value: newinfo, valueupdate:'afterkeydown'" style="width: 196px" /> <button data-bind="click: addinfo" >add</button> <br/> <select size=5 style="width:200px" data-bind="options: infos, value: selectedinfo"> </select> <button data-bind="click: removeinfo">remove selected</button> </p>

here javascript

_self.newinfo = ko.observable(""); _self.selectedinfo = ko.observable(); _self.infos = ko.observablearray(); _self.addinfo = function() { if(_self.newinfo() != "") { var validateinput = inputchecker(_self.newinfo(), _self.nfield); if(validateinput == "") { var is_unique = true; $.each( _self.infos(), function( key, val ) { if(val == _self.newinfo()) { is_unique = false; _self.newinfo(""); console.log("first"); } }); if(is_unique) { _self.infos.push( _self.newinfo() ); _self.newinfo(""); console.log("second"); } else { alert("duplicate entry"); } } else { alert(validateinput); } } else { alert("nothing add"); } homecoming false; _self.newinfo(""); }; _self.removeinfo = function() { _self.infos.remove( _self.selectedinfo() ); }; }

you can't execute code after homecoming statement, sec line here has no effect:

return false; _self.newinfo("");

just swap them:

_self.newinfo(""); homecoming false;

javascript knockout.js

No comments:

Post a Comment