www.webdeveloper.com
Results 1 to 3 of 3

Thread: save textarea.value before page refresh, then recall it

  1. #1
    Join Date
    Nov 2009
    Posts
    12

    save textarea.value before page refresh, then recall it

    When a user is using internet explorer, I need a function that saves the text from within a textarea, and then refreshes the page, and then places the saved text back into the text area. Is this possible? Here's my code so far...



    Code:
    function RefreshIfIE(element_id) {
    
    var browserName=navigator.appName; 
     var st1=document.getElementById(element_id).value;
     if (browserName=="Microsoft Internet Explorer")
     {
    
     document.location.reload(false); 
     document.getElementById(element_id).value=st1;
     }
     else
      {   }
    }

  2. #2
    Join Date
    Feb 2010
    Posts
    184

  3. #3
    Join Date
    Nov 2009
    Posts
    12

    Thanks.. almost there?

    Thanks letmehaveago.

    I followed your advice and used the following code. It says "object expected" as the error for the bolded line. I've tried a few different combinations, including specifying the id ('textfield') instead of element_id...

    Any thoughts would be appreciated!

    Thanks

    Code:
    function createCookie(name,value,days) {
    	if (days) {
    		var date = new Date();
    		date.setTime(date.getTime()+(days*24*60*60*1000));
    		var expires = "; expires="+date.toGMTString();
    	}
    	else var expires = "";
    	document.cookie = name+"="+value+expires+"; path=/";
    }
    
    function readCookie(name) {
    	var nameEQ = name + "=";
    	var ca = document.cookie.split(';');
    	for(var i=0;i < ca.length;i++) {
    		var c = ca[i];
    		while (c.charAt(0)==' ') c = c.substring(1,c.length);
    		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    	}
    	return null;
    }
    
    function eraseCookie(name) {
    	createCookie(name,"",-1);
    }
    
    
    
    function ReloadIfIE(element_id) {
    
    var browserName=navigator.appName; 
     
     if (browserName=="Microsoft Internet Explorer")
     {CreatCookie('savedstr', document.getElementById(element_id).value, 1);
     document.location.reload(false); 
     document.getElementById(element_id).value=ReadCookie('savedstr');
     EraseCookie('savedstr');
     }
     else
      {   }
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles