Solved

javascript to submit form to referrer

Posted on 2011-03-11
2
684 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now