cookies - recall form value not working for textareas -


im trying modify script

http://www.dynamicdrive.com/dynamicindex16/formremember2.htm

to work textareas, , not input text boxes. heres im guessing relevant parts of script, cant figure out myself

rememberform.prototype.savevalues=function(){ //get form values , store in cookie (var i=0; i<this.fields.length; i++){ if (this.fields[i].type=="text") this.cookiestr+=this.fields[i].fname+":"+escape(this.fields[i].value)+"#" } if (typeof this.togglebox!="undefined"){ //if "remember values checkbox" defined this.persistdays=(this.togglebox.checked)? this.persistdays : -1 //decide whether       save form values this.cookiestr=(this.togglebox.checked)? this.cookiestr+"toggleboxid:on;" :   this.cookiestr } else //if checkbox isn't defined, remove final "#" cookie string this.cookiestr=this.cookiestr.substr(0, this.cookiestr.length-1)+";" setcookie(this.cookiename, this.cookiestr, this.persistdays) }  rememberform.prototype.recallvalues=function(){ //populate form saved values var cookievalue=getcookie(this.cookiename) if (cookievalue!=""){ //parse cookie, cookie looks like:  field1:value1#field2:value2... var cookievaluepair=cookievalue.split("#") (var i=0; i<cookievaluepair.length; i++){ if (cookievaluepair[i].split(":")[0]!="toggleboxid" && this.getfield(cookievaluepair[i].split(":")[0]).type=="text") this.getfield(cookievaluepair[i].split(":")         [0]).value=unescape(cookievaluepair[i].split(":")[1]) else //else if name in name/value pair "toggleboxid" this.togglebox.checked=true } } 

the method persistfields(id, ...) sets fields want persist in cookie. fields looked id guess adding textarea id attribute suffice.

for example:

<form id="myformid">     <input type="text" id="someinputid" />     <textarea id="textareaid"></textarea> </form>  <script>     var f = new rememberform('myformid');     f.persistfields('someinputid', 'textareaid'); </script> 

this add input , textarea rememberform instance fields property.


update

the problem lies in method of rememberform. formatted code readability since original source has horrible formatting.

rememberform.prototype.savevalues = function() {      (var = 0; < this.fields.length; i++) {          // problem: allows type="text"         if (this.fields[i].type == "text") {             this.cookiestr += this.fields[i].fname + " : " + escape(this.fields[i].value) + "#"         }         if (typeof this.togglebox != "undefined") {             this.persistdays = (this.togglebox.checked) ? this.persistdays : -1;             this.cookiestr = (this.togglebox.checked) ? this.cookiestr + "toggleboxid:on;" : this.cookiestr         } else {             this.cookiestr = this.cookiestr.substr(0, this.cookiestr.length - 1) + ";"             setcookie(this.cookiename, this.cookiestr, this.persistdays)         }     } } 

as mentioned in comment test type of input element 'text'. if you'd add textareas in cookie change line to:

if (this.fields[i].type == "text" || this.fields[i].type == 'textarea') { 

that should work.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -