SebastianOpperman
SebastianOpperman

Reputation: 7326

write GET URL variable to page using javascript

I have a form which contains a wysiwyg editor. The form data is sent to a page using a GET method in the form.

How would i decode(to keep the DIV and BR tags) in the variable and print it out on the page using Javascript?

Any help would be appreciated

Upvotes: 1

Views: 1147

Answers (2)

Shae Petersen
Shae Petersen

Reputation: 58

The equivalent of decode would be unescape(), you should be able to something like this:

(function(){ 
   document.$_GET = [];
   var urlHalves = String(document.location).split('?');
   if(urlHalves[1]){
      var urlVars = urlHalves[1].split('&');
      for(var i=0; i<=(urlVars.length); i++){
         if(urlVars[i]){
            var urlVarPair = urlVars[i].split('=');
            document.$_GET[urlVarPair[0]] = urlVarPair[1];
         }
      }
   }
})();

document.write(unescape(document.$_GET['varname']));

Upvotes: 1

Squaremaster
Squaremaster

Reputation: 1

Maybe you should try this script: http://www.webtoolkit.info/javascript-url-decode-encode.html It encodes decodes everything.

Upvotes: 0

Related Questions