Solved

javascript to submit form to referrer

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

717 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