Solved

javascript to submit form to referrer

Posted on 2011-03-11
2
691 Views
Last Modified: 2012-05-11
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?
0
Comment
Question by:eaweb
2 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 35110392
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

0
 
LVL 58

Accepted Solution

by:
amit_g earned 500 total points
ID: 35110401
<form name="refer" action="" method="get">
              <input type="submit" name="Submit" value="Continue" class="buttonNormal">&nbsp;&nbsp;
              <input type="button" name="Submit" value="Close" class="buttonNormal" onClick="window.close()">
</form>

<script>
document.forms["refer"].action = getQueryVariable('referrer');
</script>

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question