# Javascript: Passing a variable to another page

**URL:** <https://forum.kirupa.com/t/javascript-passing-a-variable-to-another-page/248833>\
**Category:** web dev\
**Created:** [January 12, 2008, 1:19am UTC](https://forum.kirupa.com/t/javascript-passing-a-variable-to-another-page/248833 "2008-01-12T01:19:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)\
**Post date:** [January 12, 2008, 1:19am UTC](https://forum.kirupa.com/t/javascript-passing-a-variable-to-another-page/248833/1 "2008-01-12T01:19:32Z")

</div>

I’m working on passing a variable from a menu link to another HTML page which contains a Flash object. I need Flash to read the variable. But first, I need to know how to strip some quotes from around the value that is passed.

The first HTML page has links that look like this:

```auto

<a href='GetParam_2.html?element=Antimony'>Antimony</a><br>
<a href='GetParam_2.html?element=Barium'>Barium</a><br>
<a href='GetParam_2.html?element=Cadmium'>Cadmium</a><br>

```

The receiving HTML page has some JS script between the HEAD tags that looks like this:

```auto

<script type="text/javascript">
function GetParam(elem)
{
  var start=location.search.indexOf("?"+elem+"=");
  if (start<0) start=location.search.indexOf("&"+elem+"=");
  if (start<0) return '';
  start += elem.length+2;
  var end=location.search.indexOf("&",start)-1;
  if (end<0) end=location.search.length;
  var result='';
  for(var i=start;i<=end;i++) {
    var c=location.search.charAt(i);
    result=result+(c=='+'?' ':c);
  }
  return unescape(result);
  //Pass the data to Flash
  window.document.movie.SetVariable("element", elem);
}
</script>       

```

And between the BODY tags:

```auto

<p>'<script type="text/javascript"><!--
//document.write(location.search)
document.write(GetParam('element'));
// --></script>'</p>

```

(This is just to test that the variable has been received. I can’t remove the single quotes from ‘element’ and have it work. But document.write wants to print ‘Antimony’ (in quotes). I need to remove the quotes from that string. Suggestions please!
