-1

I've got a Javascript script that sends 4 variables to a php page.

The fact is that, if one (or more) of these variables contain a character such as "&" or "%", it just won't work, it only sends what there was before "&" or "%". For instance, if the content of a variable is "Bolliger&Mabillard", the result will be "Bolliger". Obviously, this happens because the script separate each variable with an "&", how can I solve this?

Here's the script I'm talking about

<script type="text/javascript">
function save() 
{ 
 var shortname=location.hostname.replace(/^(www.|)([\w]+)(\..+|)/g, "$2");
 var url="http://"+window.location.hostname+"/";
 var link=window.location.href;
 var link_title="Bolliger&Mabillard"; 
 window.open("http://www.example.com/add.php?url=" + url + "&shortname="+shortname + "&link="+link + "&link_title="+link_title);
} 
</script>
John Saunders
  • 160,644
  • 26
  • 247
  • 397
gigapico00
  • 417
  • 1
  • 7
  • 24
  • http://stackoverflow.com/questions/3541711/javascript-url-encode – user229044 Oct 26 '14 at 02:39
  • Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See "[Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). BTW, it's "Thanks in advance", not "Thanks in advantage". That doesn't even make _sense_. – John Saunders Mar 17 '15 at 10:58

1 Answers1

1

You need to URL-encode the values using encodeURIComponent().

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964