Link to home
Start Free TrialLog in
Avatar of eaweb
eawebFlag for undefined

asked on

javascript to submit form to referrer

Hi

I have the following javascript that get the referrer url from this link (http://home.group.csd/online/weblink.htm?referrer=http://www.adobe.com/products/acrobat/readstep2.html)

<script type="text/javascript">
function getQueryVariable(referrer) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var x=0; x<vars.length; x++) {
    var pair = vars[x].split("=");
    if (pair[0] == referrer) {
        return pair[1];
    }
  }
  //alert('Query Variable ' + referrer + ' not found');
}
</script>

Using below form when submitting it i want the page to go to the referrer url (http://www.adobe.com/products/acrobat/readstep2.html)

<form name="refer" action="javascript:getQueryVariable('referrer')" method="get">
<input type="submit" name="Submit" value="Continue" class="buttonNormal">&nbsp;&nbsp;
              <input type="button" name="Submit" value="Close" class="buttonNormal" onClick="javascript:window.close()">
</form>

But in some way it is not working. What need to be done for the form to work? Is there a better way than what i have above?
Avatar of sjklein42
sjklein42
Flag of United States of America image

Try it this way:

<script type="text/javascript"> 
function getQueryVariable(referrer) { 
  var query = window.location.search.substring(1); 
  var vars = query.split("&"); 
  for (var x=0; x<vars.length; x++) { 
    var pair = vars[x].split("="); 
    if (pair[0] == referrer) { 
        return pair[1]; 
    } 
  } 
  //alert('Query Variable ' + referrer + ' not found'); 
} 

document.write('<form name="refer" action="'+getQueryVariable('referrer')+'" method="get">');
document.write('<input type="submit" name="Submit" value="Continue" class="buttonNormal">&nbsp;&nbsp;');
document.write('<input type="button" name="Submit" value="Close" class="buttonNormal" onClick="javascript:window.close()">');
document.write('</form>');
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial