?
Solved

javascript to submit form to referrer

Posted on 2011-03-11
2
Medium Priority
?
701 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
Suggested Courses

770 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