-1

I got a code which let me change a value in an another page using a form submit in Javascript, the problem is that the url does not accept the value @ (@ = %40 in the url)

here is the code:

index.html

<form method="GET" action="page.html">
  <input type="text" id="my_text" name="my_text" />
  <input type="submit" />
</form>

page.html

<input id="title"></input>

<script type="text/javascript">
  function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, 
          function(m,key,value) {
      vars[key] = value;
    });
    return vars;
  }
  document.getElementById("title").value = getUrlVars()["my_text"];
</script>

How can I fix this problem?

Horai Nuri
  • 5,358
  • 16
  • 75
  • 127

2 Answers2

0

You probably want to use encodeURI(), see this answer for an in depth explanation.

Community
  • 1
  • 1
Shakeel
  • 1,039
  • 7
  • 20
0

I found the answer, I had to use decodeURIComponent(), which let me get the correct value.

Horai Nuri
  • 5,358
  • 16
  • 75
  • 127