5 Replies - 1021 Views - Last Post: 12 November 2010 - 01:16 AM

#1 rjschu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 12-February 09

replace characters

Posted 11 November 2010 - 02:23 PM

i am transferring data from one form to another by passing the data into the url, but when i place on the next form it shows up with + signs from the url aswell i have a piece of code in there that should be replacing it with just a space but it doesnt seem to be working, any advice?

here is my code:
function getValue(varname)
{
  var url = window.location.href;
  var qparts = url.split("?");
  if (qparts.length == 0)
  {
    return "";
  }
  var query = qparts[1];
  var vars = query.split("&");
  var value = "";
  for (i=0;i<vars.length;i++)
  {
  var parts = vars[i].split("=");
  if (parts[0] == varname)
  {
  value = parts[1];
  break;
   }
  }
  value = unescape(value);
  value.replace(/\+/g," ");
  return value;
}



Is This A Good Question/Topic? 0
  • +

Replies To: replace characters

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: replace characters

Posted 11 November 2010 - 03:02 PM

Replace returns a string... so you need to capture its result...

return value.replace(/\+/g," ");



Here we are returning the string that is returned by the replace. Since you weren't saving, or returning, the result then it was returning the value for the variable "value" after it returned from unescape().

:)
Was This Post Helpful? 0
  • +
  • -

#3 rjschu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 12-February 09

Re: replace characters

Posted 11 November 2010 - 05:44 PM

that is brilliant thank you i have been struggling with that for a while.

any chance you know how to load a css dependent upon the browser type i have tried using:

   var browser = navigator.appCode.toLowerCase();
      
     if(browser = 'microsoft internet explorer'){
      document.getElementById('default').href = 'iejassignment.css';
      }



Was This Post Helpful? 0
  • +
  • -

#4 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: replace characters

Posted 11 November 2010 - 06:06 PM

Try using appName, not appCode and when you compare, remember to use TWO equal signs, not one.

Then if you want to apply a specific style to an element on the page, try using "className" to assign a CSS class to the element...

function ChangeColor() {
    var browser = navigator.appName.toLowerCase();
   
    if(browser == 'microsoft internet explorer'){
       document.getElementById('default').className = "ieclass";
    }
}



Then if we have a CSS class style named "ieclass" for IE like...

.ieclass { color: #FF0000; }



Then we could apply this class on a button click if the browser was IE only. The HTML would be like this...

<div id="default">Hello</div>

<input type="button" value="Click" onclick="ChangeColor()"/>



In essence they click the button, it calls our javascript which checks if the browser we are using is IE. If it is, then it will apply the "ieclass" style to the element with the id "default" making hello red. The same code in Firefox or any other browser will not do anything since it is not IE.

Enjoy! :)
Was This Post Helpful? 0
  • +
  • -

#5 rjschu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 12-February 09

Re: replace characters

Posted 11 November 2010 - 07:40 PM

how do i use this to position a div on the page? because im trying to position a div at the bottom of the page and in IE it positions it to low?

and im using an external style sheet?

actually its ok I figured it out thank you for your help it is greatly appreciated.

Thank you again.
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3524
  • View blog
  • Posts: 10,164
  • Joined: 08-June 10

Re: replace characters

Posted 12 November 2010 - 01:16 AM

View Postrjschu, on 11 November 2010 - 09:23 PM, said:

  value = unescape(value);
  value.replace(/\+/g," ");


you could use the Javascript decoding functions (decodeURI()/decodeURIComponent()) for this …
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1